#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
vector<long long>v;
int taken [101][101];
struct r
{
	long long a,b,c,d;
	r(long long a,long long b,long long c,long long d)
	{
		this->a=a;
		this->b=b;
		this->c=c;
		this->d=d;
	}
};
vector<r>store;
int has[101][101];
int main()
{
	long long n,i,p,j,q,k;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>p;
		v.push_back(p);
	}
	for(i=0;i<v.size();i++)
	{
		for(j=0;j<v[i];j++)
		{
			cin>>q;
			taken[i][j]=q;

		}
	}

	for(i=v.size()-1;i>=0;i--)
	{
		for(k=0;k<v[i];k++)
		{
			long long value=taken[i][k];
			int ma=10000000;
			int s,e;
			for(int l=0;l<v.size();l++)
			{
				for(int p=0;p<v[l];p++)
				{
					if(has[l][p]==0)
					{
						if(taken[l][p]<ma)
						{
							ma=taken[l][p];
							s=l;
							e=p;
						}
					}
				}
			}
			if(value==ma)
			{
				has[i][k]=1;

			}
			else
			{
				store.push_back(r(i+1,k+1,s+1,e+1));
				swap(taken[i][k],taken[s][e]);
				has[i][k]=1;
			}

		}
	}
	cout<<store.size()<<"\n";
	for(i=0;i<store.size();i++)
	{
		cout<<store[i].a<<" "<<store[i].b<<" "<<store[i].b<<" ";
		cout<<store[i].c<<"\n";
	}

}


#pragma comment (linker,"/stack:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <map>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
const int N = 55;
const int M = 200005;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const double Pi = acos(-1.0);

#define Key_value ch[ch[root][1]][0]
#define lson (i<<1)
#define rson (i<<1|1)

int lowbit(int x) { return x & (-x); }
template < class T > inline T f_min(T a, T b) { return a < b ? a : b; }
template < class T > inline T f_max(T a, T b) { return a > b ? a : b; }
template < class T > inline T f_abs(T a) { return a > 0 ? a : -a; }
template < class T > inline T f_gcd(T a, T b) { return b == 0 ? a : f_gcd(b, a%b); }
template < class T > inline T f_Lcm(T a, T b) { return a / f_gcd(a, b) * b; }
template < class T > inline void f_swap(T &a, T &b) { T t = a;a = b;b = t; }
bool is_digit(char a) { if (a >= '0' && a <= '9')return true;return false; }
bool is_lowch(char a) { if (a >= 'a' && a <= 'z')return true;return false; }
bool is_upch(char a) { if (a >= 'A' && a <= 'Z')return true;return false; }

int main() {
    int n, a[N], ans[N][N];
    pair<int, int>  loc[N*N];
    pair<pair<int, int>, pair<int, int> >   res[N*N];
    while (cin>>n) {
        for (int i = 0;i < n;++i)   cin >> a[i];
        for (int i = 0;i < n;++i)
            for (int j = 0;j < a[i];++j)cin >> ans[i][j]
            ,loc[ans[i][j]] = make_pair(i+1, j+1);
        int num = 0;
        for (int i = 0,cnt = 1;i < n;++i) {
            for (int j = 0;j < a[i];++j,cnt++)if (ans[i][j] != cnt) {
                //cout << i << " " << j << " " << loc[cnt].first << " " << loc[cnt].second << endl;
                res[num++] = make_pair(make_pair(i+1,j+1),loc[cnt]);
                int temp = ans[i][j];
                f_swap(ans[i][j],ans[loc[cnt].first-1][loc[cnt].second-1]);
                //cout << ans[i][j] << " " << ans[loc[cnt].first - 1][loc[cnt].second - 1] << endl;
                f_swap(loc[temp],loc[cnt]);
            }
        }
        /*
        for (int i = 0;i < n;++i) {
            for (int j = 0;j < a[i];++j)cout << ans[i][j] << " ";
            cout << endl;
        }*/
        cout << num << endl;
        for (int i = 0;i < num;++i)
            cout << res[i].first.first << " " << res[i].first.second << " " << res[i].second.first << " " << res[i].second.second << endl;
    }
    return 0;
}


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle l+r>>1
typedef pair<int,int> pii;
typedef multiset<int> mset;
typedef multiset<int>::iterator mst_it;

template <class T> T _max(T x,T y){return x>y? x:y;}
template <class T> T _min(T x,T y){return x<y? x:y;}
template <class T> void _swap(T &x,T &y){T z=x;x=y;y=z;}
template <class T> T GCD(T a,T b){for(T t;b;t=a%b,a=b,b=t);return a;}
template <class T> T LCM(T a,T b){return a/GCD(a,b)*b;}
#define clr_all(x,num) memset(x,num,sizeof(x))
#define clr(x,num,sz) memset(x,num,sizeof(x[0])*(sz+1))
#define inf 0x3F3F3F3F
#define eps (1e-9)
#define MOD 1000000007
const double pi=acos(-1.0);
const int M=55;
const ll N=1000000;
int ts,cas=0;

int n,m;
int c[M*M],a[M][M];
struct node{
    int x,y;
};
node init[M*M],now[M*M];
node ans[M*M][2];

void run(){
    int i,j,s=0,ss=0;
    for(i=1;i<=n;i++){
        scanf("%d",&c[i]);
        s+=c[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=c[i];j++){
            scanf("%d",&a[i][j]);
            init[a[i][j]].x=i;
            init[a[i][j]].y=j;
            ++ss;
            now[ss].x=i;
            now[ss].y=j;
        }
    }
    for(i=1,m=0;i<=s;i++){
        j=a[now[i].x][now[i].y];
        if(j == i) continue;
        ++m;
        ans[m][0]=init[i];
        ans[m][1]=init[j];
        swap(a[init[i].x][init[i].y],a[init[j].x][init[j].y]);
        init[j].x=init[i].x;
        init[j].y=init[i].y;
    }
    /*for(i=1;i<=n;i++)
        for(j=1;j<=c[i];j++)
            printf("%d%c",a[i][j],(j==c[i])? '\n':' ');*/
    printf("%d\n",m);
    for(i=1;i<=m;i++)
        printf("%d %d %d %d\n",ans[i][0].x,ans[i][0].y,ans[i][1].x,ans[i][1].y);
    //puts("------------------");
}

void preSof(){
}

int main(){
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    preSof();
    //run();
    while(~scanf("%d",&n)) run();
    //for(scanf("%d",&ts),cas=1;cas<=ts;cas++) run();
    return 0;
}


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle l+r>>1
typedef pair<int,int> pii;
typedef multiset<int> mset;
typedef multiset<int>::iterator mst_it;

template <class T> T _max(T x,T y){return x>y? x:y;}
template <class T> T _min(T x,T y){return x<y? x:y;}
template <class T> void _swap(T &x,T &y){T z=x;x=y;y=z;}
template <class T> T GCD(T a,T b){for(T t;b;t=a%b,a=b,b=t);return a;}
template <class T> T LCM(T a,T b){return a/GCD(a,b)*b;}
#define clr_all(x,num) memset(x,num,sizeof(x))
#define clr(x,num,sz) memset(x,num,sizeof(x[0])*(sz+1))
#define inf 0x3F3F3F3F
#define eps (1e-9)
#define MOD 1000000007
const double pi=acos(-1.0);
const int M=55;
const ll N=1000000;
int ts,cas=0;

int n,m;
int c[M],a[M][M];
struct node{
    int x,y;
};
node init[M],now[M];
node ans[M][2];

void run(){
    int i,j,s=0,ss=0;
    for(i=1;i<=n;i++){
        scanf("%d",&c[i]);
        s+=c[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=c[i];j++){
            scanf("%d",&a[i][j]);
            init[a[i][j]].x=i;
            init[a[i][j]].y=j;
            ++ss;
            now[ss].x=i;
            now[ss].y=j;
        }
    }
    for(i=1;i<=s;i++){
        j=a[now[i].x][now[i].y];
        if(j == i) continue;
        ++m;
        ans[m][0]=init[i];
        ans[m][1]=init[j];
        swap(a[init[i].x][init[i].y],a[init[j].x][init[j].y]);
        init[j].x=init[i].x;
        init[j].y=init[i].y;
    }
    //for(i=1;i<=n;i++)
    //  for(j=1;j<=c[i];j++)
    //      printf("%d%c",a[i][j],(j==c[i])? '\n':' ');
    printf("%d\n",m);
    for(i=1;i<=m;i++)
        printf("%d %d %d %d\n",ans[i][0].x,ans[i][0].y,ans[i][1].x,ans[i][1].y);
    //puts("------------------");
}

void preSof(){
}

int main(){
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    preSof();
    //run();
    while(~scanf("%d",&n)) run();
    //for(scanf("%d",&ts),cas=1;cas<=ts;cas++) run();
    return 0;
}


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ls rt<<1
#define rs ls|1
#define lson l,mid,ls
#define rson mid+1,r,rs
#define middle l+r>>1
typedef pair<int,int> pii;
typedef multiset<int> mset;
typedef multiset<int>::iterator mst_it;

template <class T> T _max(T x,T y){return x>y? x:y;}
template <class T> T _min(T x,T y){return x<y? x:y;}
template <class T> void _swap(T &x,T &y){T z=x;x=y;y=z;}
template <class T> T GCD(T a,T b){for(T t;b;t=a%b,a=b,b=t);return a;}
template <class T> T LCM(T a,T b){return a/GCD(a,b)*b;}
#define clr_all(x,num) memset(x,num,sizeof(x))
#define clr(x,num,sz) memset(x,num,sizeof(x[0])*(sz+1))
#define inf 0x3F3F3F3F
#define eps (1e-9)
#define MOD 1000000007
const double pi=acos(-1.0);
const int M=55;
const ll N=1000000;
int ts,cas=0;

int n,m;
int c[M*M],a[M][M];
struct node{
    int x,y;
};
node init[M*M],now[M*M];
node ans[M*M][2];

void run(){
    int i,j,s=0,ss=0;
    for(i=1;i<=n;i++){
        scanf("%d",&c[i]);
        s+=c[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=c[i];j++){
            scanf("%d",&a[i][j]);
            init[a[i][j]].x=i;
            init[a[i][j]].y=j;
            ++ss;
            now[ss].x=i;
            now[ss].y=j;
        }
    }
    for(i=1;i<=s;i++){
        j=a[now[i].x][now[i].y];
        if(j == i) continue;
        ++m;
        ans[m][0]=init[i];
        ans[m][1]=init[j];
        //swap(a[init[i].x][init[i].y],a[init[j].x][init[j].y]);
        init[j].x=init[i].x;
        init[j].y=init[i].y;
    }
    //for(i=1;i<=n;i++)
    //  for(j=1;j<=c[i];j++)
    //      printf("%d%c",a[i][j],(j==c[i])? '\n':' ');
    printf("%d\n",m);
    for(i=1;i<=m;i++)
        printf("%d %d %d %d\n",ans[i][0].x,ans[i][0].y,ans[i][1].x,ans[i][1].y);
    //puts("------------------");
}

void preSof(){
}

int main(){
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    preSof();
    //run();
    while(~scanf("%d",&n)) run();
    //for(scanf("%d",&ts),cas=1;cas<=ts;cas++) run();
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int n, c[52], a[52][52], x, y, _x, _y, cnt, ii;
vector< vector<int> > ans;
bool check()
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < c[i]-1; j++)
        {
            if (c[i] > j+1 && a[i][j+1] < a[i][j])
                return false;
            if (c[i+1] > j && a[i+1][j] < a[i][j])
                return false;
        }
    }
    return true;
}

void fnd(int k, int &x, int &y)
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < c[i]; j++)
            if (a[i][j] == k)
            {
                x = j, y = i;
                return;
            }

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < c[i]; j++)
            cin >> a[i][j];
    for (ii = 1; !check(); ii++)
    {
        fnd(ii, x, y);
        if (a[y][x] != a[_y][_x])
        {
        ans.resize(ans.size()+1);
        ans[cnt].push_back(y+1);
        ans[cnt].push_back(x+1);
        ans[cnt].push_back(_y+1);
        ans[cnt].push_back(_x+1);
        swap(a[y][x], a[_y][_x]);
        cnt++;
        }
        if (c[_y+1] > _x)
            _y++;
        else
            _y = 0, _x++;
    }
    cout << cnt << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        for (int j = 0; j < 4; j++)
            cout << ans[i][j] << ' ';
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int n, c[52], a[52][52], x, y, _x, _y, cnt;
vector< vector<int> > ans;
bool check()
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < c[i]-1; j++)
        {
            if (c[i] > j+1 && a[i][j+1] < a[i][j])
                return false;
            if (c[i+1] > j && a[i+1][j] < a[i][j])
                return false;
        }
    }
    return true;
}

void fnd(int k, int &x, int &y)
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < c[i]; j++)
            if (a[i][j] == k)
            {
                x = j, y = i;
                return;
            }

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < c[i]; j++)
            cin >> a[i][j];
    for (int i = 1; !check(); i++)
    {
        fnd(i, x, y);
        if (a[y][x] == a[_y][_x])
            continue;
        ans.resize(ans.size()+1);
        ans[cnt].push_back(y+1);
        ans[cnt].push_back(x+1);
        ans[cnt].push_back(_y+1);
        ans[cnt].push_back(_x+1);
        swap(a[y][x], a[_y][_x]);
        cnt++;
        if (c[_y+1] > _x)
            _y++;
        else
            _y = 0, _x++;
    }
    cout << cnt << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        for (int j = 0; j < 4; j++)
            cout << ans[i][j] << ' ';
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int n, c[52], a[52][52], x, y, _x, _y, cnt, ii;
vector< vector<int> > ans;
bool check()
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < c[i]; j++)
        {
            if (c[i] > j+1 && a[i][j+1] < a[i][j])
                return false;
            if (c[i+1] > j && a[i+1][j] < a[i][j])
                return false;
        }
    }
    return true;
}

void fnd(int k, int &x, int &y)
{
    for (int i = 0; i < n; i++)
        for (int j = 0; j < c[i]; j++)
            if (a[i][j] == k)
            {
                x = j, y = i;
                return;
            }

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < c[i]; j++)
            cin >> a[i][j];
    for (ii = 1; !check(); ii++)
    {
        fnd(ii, x, y);
        if (a[y][x] != a[_y][_x])
        {
        ans.resize(ans.size()+1);
        ans[cnt].push_back(y+1);
        ans[cnt].push_back(x+1);
        ans[cnt].push_back(_y+1);
        ans[cnt].push_back(_x+1);
        swap(a[y][x], a[_y][_x]);
        cnt++;
        }
        if (c[_y+1] > _x)
            _y++;
        else
            _y = 0, _x++;
    }
    cout << cnt << endl;
    for (int i = 0; i < ans.size(); i++)
    {
        for (int j = 0; j < 4; j++)
            cout << ans[i][j] << ' ';
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int n;
int c[60];
int a[60][60];
int ag[60][60];

pair<int,int> findG(int x){
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < c[i]; j ++){
            if(ag[i][j] == x)
                return make_pair(i,j);
        }
    }
    return make_pair(-1,-1);
}

pair<int,int> findA(int x){
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < c[i]; j ++){
            if(a[i][j] == x)
                return make_pair(i,j);
        }
    }
    return make_pair(-1,-1);
}

int main(){
    memset(a, -1, sizeof(a));
    memset(ag, -1, sizeof(ag));
    scanf("%d", &n);
    for(int i = 0; i < n; i ++){
        scanf("%d", &c[i]);
    }
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < c[i]; j ++){
            scanf("%d", &a[i][j]);
            if(i!=0)
            ag[i][j] = ag[i-1][c[i-1]-1]+1+j;
            else
            ag[i][j] = j+1;
        }
    }
    pair<int, int> res;
    pair<int, int> resG;
    int num = 1;
    res = findA(num);
    int move = 0;
    pair<pair<int, int>, pair<int, int> > mov[3600];
    while(res.first != -1){
        resG = findG(num);
        if(res != resG){
            swap(a[resG.first][resG.second], a[res.first][res.second]);
            mov[move].first.first = res.first+1;
            mov[move].first.second = res.second+1;
            mov[move].second.first = resG.first+1;
            mov[move].second.second = resG.second+1;
            move ++;
        }
        num ++;
        res = findA(num);
    }
    cout << move << endl;
    for(int i = 0; i < move; i++){
        cout << mov[i].first.first << " " << mov[i].first.second << " ";
        cout << mov[i].second.first << " " << mov[i].second.second << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <string>

using namespace std;

#define int64 long long

string intto(int x){
    string res = "";
    while (x)
    {
        int cur = x % 10;
        string t = "a";
        t[0] = cur + '0';
        res += t;
        x /= 10;
    }
    reverse(res.begin(), res.end());
    return res;
}

int main(){
    int n;
    int c[55];
    int a[55][55];
    vector<string> m;
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> c[i];
    }
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < c[i]; j ++){
            cin >> a[i][j];
        }
    }
    for(int k = 0; k < 52; k++)
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < c[i]; j ++){
            if(j > 0){
                if(a[i][j]<a[i][j-1]){
                    swap(a[i][j],a[i][j-1]);
                    m.push_back(intto(i+1)+" "+intto(j+1)+" "+intto(i+1)+" "+intto(j));
                }
            }
            if(i > 0){
                if(a[i][j]<a[i-1][j]){
                    swap(a[i][j],a[i-1][j]);
                    m.push_back(intto(i+1)+" "+intto(j+1)+" "+intto(i)+" "+intto(j+1));
                }
            }
        }
    }
    for(int i = 0; i < m.size(); i ++){
        cout << m[i] << endl;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++)
            cin >> a[i][j];
    }
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < c[i]; j++) {
            int mx = 0, t = 0;
            if (i)
                mx = a[i - 1][j], t = 1;
            if (j && mx < a[i][j - 1])
                mx = a[i][j - 1], t = 2;
            if (a[i][j] < mx) {
                if (t == 1) {
                    swap(a[i][j], a[i - 1][j]);
                    ans.pb(mp(mp(i, j), mp(i - 1, j)));
                } else {
                    swap(a[i][j], a[i][j - 1]);
                    ans.pb(mp(mp(i, j), mp(i, j - 1)));
                }
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
pii b[3000];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            cin >> a[i][j];
            b[a[i][j]] = mp(i, j);
        }
    }
    int k = 1;
    for (int j = 0; j < c[0]; j++) {
        for (int i = 0; i < n; i++) {
            if (j < c[i])
                continue;
            if (b[k].ff != i || b[k].ss != j) {
                ans.pb(mp(mp(i, j), mp(b[k].ff, b[k].ss)));
                swap(b[k], b[a[i][j]]);
            }
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
pii b[3000];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            cin >> a[i][j];
            b[a[i][j]] = mp(i, j);
        }
    }
    int k = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            if (b[k].ff != i || b[k].ss != j) {
                ans.pb(mp(b[k], b[a[i][j]]));
                swap(b[k], b[a[i][j]]);
                swap(a[ans.back().ff.ff][ans.back().ff.ss], a[ans.back().ss.ff][ans.back().ss.ss]);
            }
            k++;
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
pii b[3000];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            cin >> a[i][j];
            b[a[i][j]] = mp(i, j);
        }
    }
    int k = 1;
    for (int j = 0; j < c[0]; j++) {
        for (int i = 0; i < n; i++) {
            if (j >= c[i])
                continue;
            if (b[k].ff != i || b[k].ss != j) {
                ans.pb(mp(mp(i, j), mp(b[k].ff, b[k].ss)));
                swap(b[k], b[a[i][j]]);
            }
            k++;
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
pii b[3000];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            cin >> a[i][j];
            b[a[i][j]] = mp(i, j);
        }
    }
    int k = 1;
    for (int j = 0; j < c[0]; j++) {
        for (int i = 0; i < n; i++) {
            if (j >= c[i])
                continue;
            if (b[k].ff != i || b[k].ss != j) {
                ans.pb(mp(mp(i, j), mp(b[k].ff, b[k].ss)));
                swap(b[k], b[a[i][j]]);
            }
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
pii b[3000];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            cin >> a[i][j];
            b[a[i][j]] = mp(i, j);
        }
    }
    int k = 1;
    for (int j = 0; j < c[0]; j++) {
        for (int i = 0; i < n; i++) {
            if (j >= c[i])
                continue;
            if (b[k].ff != i || b[k].ss != j) {
                ans.pb(mp(mp(i, j), b[k]));
                swap(b[k], b[a[i][j]]);
            }
            k++;
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <ctime>

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define sqr(x) (((x) + .0) * ((x) + .0))

typedef long long ll;
typedef double db;
typedef pair<int, int> pii;

const int maxn = 100500;
const int infi = (1 << 30);
const ll infl = (1LL << 62);
const db eps = 1e-9;

int n;
int c[55], a[55][55];
pii b[3000];
vector< pair<pii, pii> > ans;

int main() {

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            cin >> a[i][j];
            b[a[i][j]] = mp(i, j);
        }
    }
    int k = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            if (b[k].ff != i || b[k].ss != j) {
                ans.pb(mp(b[k], b[a[i][j]]));
                swap(b[k], b[a[i][j]]);
            }
            k++;
        }
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].ff.ff + 1 << " " << ans[i].ff.ss + 1 << " " << ans[i].ss.ff + 1 << " " << ans[i].ss.ss + 1 << endl;

    return 0;
}


#include <iostream>

using namespace std;

int a[51][51];
int aid[51][51];

void swap(int &x, int &y)
{
	int temp = x;
	x = y;
	y = temp;
}

struct res
{
	int x1, y1, x2, y2;
};

int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	int n;
	res M[2501];
	int ind = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i][0];
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= a[i][0]; j++)
			cin >> a[i][j];
	int temp = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= a[i][0]; j++)
			aid[i][j] = ++temp;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= a[i][0]; j++)
			if(a[i][j] != aid[i][j])
			{
				bool flag = true;
				for(int k = 1; k <= n; k++)
				{
					if(!flag) break;
					for(int m = 1; m <= a[k][0]; m++)
					{
						if(!flag) break;
						if(a[k][m] == aid[i][j])
						{
							M[++ind].x1 = i;
							M[ind].y1 = j;
							M[ind].x2 = k;
							M[ind].y2 = m;
							flag = false;
							swap(a[i][j],a[k][m]);
						}
					}
				}
			}
	cout << ind << endl;
	for(int i = 1; i <= ind; i++)
		cout << M[i].x1 << " " << M[i].y1 << " " << M[i].x2 << " " << M[i].y2 << endl;
	fclose(stdin);
	fclose(stdin);
	return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>
#include <map>
#include <set>
#define fl(i,l,r) for(int i=l;i<r;i++)
#define PB push_back
#define MP make_pair

using namespace std;

typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

struct point{double x, y; };

int n,m;
int c[55],ans[5500][4];
vector<int> a[55];

int main(){
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>c[i];
	for (int i=1; i<=n; i++)
		for (int j=0; j<c[i]; j++)
		{ int x; cin>>x; a[i].PB(x);}
	m=0;
	for (int  i=n; i>=1; i--)
		for (int j=c[i]-1; j>=0; j--){
			int maxi=0, indi=i, indj=j;

			for (int j1=j-1; j1>=0; j1--)
				if (a[i][j1]>maxi)
					maxi=a[i][j1], indi=i, indj=j1;
			for (int  i1=i-1; i1>=1; i1--)
				for (int j1=c[i1]-1; j1>=0; j1--)
					if (a[i1][j1]>maxi)
						maxi=a[i1][j1], indi=i1, indj=j1;
			if (indi!=i || indj!=j){
				ans[m][0]=i; ans[m][1]=j+1; ans[m][2]=indi; ans[m][3]=indj+1; m++;
				int tm=a[i][j];
				a[i][j]=a[indi][indj];
				a[indi][indj]=tm;
			}
		}
	cout<<m<<endl;
	for (int i=0; i<m; i++){
		cout<<ans[i][0];
		for (int j=1; j<=3; j++)
			cout<<" "<<ans[i][j];
		cout<<endl;
	}

	//system("Pause");
}


#include <algorithm>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>
#include <map>
#include <set>
#define fl(i,l,r) for(int i=l;i<r;i++)
#define PB push_back
#define MP make_pair

using namespace std;

typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

struct point{double x, y; };

const int N=1000001, M=10000;
bool is[N];
int prm[M],a,b,k;
int myp[M];

int getprm(int n){
    int i,j,k=0;
    int s,e=(int)(sqrt(0.0+n)+1);
    memset(is,1,sizeof(is));
    prm[k++]=2; is[0]=is[1]=0;
    for (i=4; i<n; i+=2) is[i]=0;
    for (i=3; i<e; i+=2)
        if (is[i]){
                prm[k++]=i;
                for (s=i*2, j=i*i; j<n; j+=s)
                    is[j]=0;
        }
    for (; i<n; i+=2)
        if (is[i]) prm[k++]=i;
    return k;
}

int main(){
    cin>>a>>b>>k;
    int m=getprm(b+1);
    int s=-1;
    for (int i=0; i<m; i++)
        if (prm[i]>=a)
        {s=i; break;};
    if (s==-1){
        cout<<-1<<endl; return 0;
    }
    for (int i=s; i<m; i++)
        myp[i-s]=prm[i];
    if (k>m-s){
        cout<<-1<<endl; return 0;
    }
    int maxi=0;
    for (int i=0; i<m-s; i++)
        if (i+k<m-s && myp[i+k]-myp[i]>maxi)
            maxi=myp[i+k]-myp[i];
    maxi=max(myp[k-1]-a+1,maxi);
    maxi=max(b-myp[m-s-k]+1,maxi);
    cout<<maxi<<endl;
    //int l=myp[k-1]-a+1;
    //while (l<=b-a+1){
    //  bool ok=1;
    //  int id=0;
    //  int np=k;
    //      for (int i=k; i<m-s && myp[i]<=myp[0]+l-1; i++)
    //  np++;
    //  //id=1;
    //  while (id <m-s && myp[id]+l-1<=b){
    //      id++;
    //      for (int i=id-1+np; i<m-s && myp[i]<=myp[id]+l-1; i++)
    //          np++;
    //      np--;
    //      if (np<k){ ok=0; break; }
    //  }
    //  if (ok){
    //      cout<<l<<endl; return 0; }
    //  else l++;
    //}
    //cout<<-1<<endl;
    //system("Pause");
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>
#include <map>
#include <set>
#define fl(i,l,r) for(int i=l;i<r;i++)
#define PB push_back
#define MP make_pair

using namespace std;

typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

struct point{double x, y; };

int n,m;
int c[55],ans[5500][4];
vector<int> a[55];

int main(){
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>c[i];
	for (int i=1; i<=n; i++)
		for (int j=0; j<c[i]; j++)
		{ int x; cin>>x; a[i].PB(x);}
	m=0;
	for (int  i=n; i>=1; i--)
		for (int j=c[i]-1; j>=0; j--){
			int maxi=a[i][j], indi=i, indj=j;

			for (int j1=j-1; j1>=0; j1--)
				if (a[i][j1]>maxi)
					maxi=a[i][j1], indi=i, indj=j1;

			for (int  i1=i-1; i1>=1; i1--)
				for (int j1=c[i1]-1; j1>=0; j1--)
					if (a[i1][j1]>maxi)
						maxi=a[i1][j1], indi=i1, indj=j1;
			if (indi!=i || indj!=j){
				ans[m][0]=i; ans[m][1]=j+1; ans[m][2]=indi; ans[m][3]=indj+1; m++;
				int tm=a[i][j];
				a[i][j]=a[indi][indj];
				a[indi][indj]=tm;
			}
		}
	cout<<m<<endl;
	for (int i=0; i<m; i++){
		cout<<ans[i][0];
		for (int j=1; j<=3; j++)
			cout<<" "<<ans[i][j];
		cout<<endl;
	}

//	system("Pause");
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>
#include <map>
#include <set>
#define fl(i,l,r) for(int i=l;i<r;i++)
#define PB push_back
#define MP make_pair

using namespace std;

typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

struct point{double x, y; };

int n,m;
int c[55],ans[5500][4];
vector<int> a[55];

int main(){
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>c[i];
	for (int i=1; i<=n; i++)
		for (int j=0; j<c[i]; j++)
		{ int x; cin>>x; a[i].PB(x);}
	m=0;
	for (int  i=n; i>=1; i--)
		for (int j=c[i]-1; j>=0; j--){
			int maxi=0, indi=i, indj=j;

			for (int j1=j-1; j1>=0; j1--)
				if (a[i][j1]>maxi)
					maxi=a[i][j1], indi=i, indj=j1;
			for (int  i1=i-1; i1>=1; i1--)
				for (int j1=c[i1]-1; j1>=0; j1--)
					if (a[i1][j1]>maxi)
						maxi=a[i1][j1], indi=i1, indj=j1;
			if (indi!=i || indj!=j){
				ans[m][0]=i; ans[m][1]=j+1; ans[m][2]=indi; ans[m][3]=indj+1; m++;

			}
		}
	cout<<m<<endl;
	for (int i=0; i<m; i++){
		cout<<ans[i][0];
		for (int j=1; j<=3; j++)
			cout<<" "<<ans[i][j];
		cout<<endl;
	}
	//system("Pause");
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stdio.h>
#include <stack>
#include <list>
#include <map>
#include <set>
#define fl(i,l,r) for(int i=l;i<r;i++)
#define PB push_back
#define MP make_pair

using namespace std;

typedef map<int,int> MII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

struct point{double x, y; };

int n,m;
int c[55],ans[5500][4];
vector<int> a[55];

int main(){
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>c[i];
	for (int i=1; i<=n; i++)
		for (int j=0; j<c[i]; j++)
		{ int x; cin>>x; a[i].PB(x);}
	m=0;
	for (int  i=n; i>=1; i--)
		for (int j=c[i]-1; j>=0; j--){
			int maxi=a[i][j], indi=i, indj=j;

			for (int j1=j-1; j1>=0; j1--)
				if (a[i][j1]>maxi)
					maxi=a[i][j1], indi=i, indj=j1;

			for (int  i1=i-1; i1>=1; i1--)
				for (int j1=c[i1]-1; j1>=0; j1--)
					if (a[i1][j1]>maxi)
						maxi=a[i1][j1], indi=i1, indj=j1;
			if (indi!=i || indj!=j){
				ans[m][0]=i; ans[m][1]=j+1; ans[m][2]=indi; ans[m][3]=indj+1; m++;
				int tm=a[i][j];
				a[i][j]=a[indi][indj];
				a[indi][indj]=tm;
			}
		}
	cout<<m<<endl;
	for (int i=0; i<m; i++){
		cout<<ans[i][0];
		for (int j=1; j<=3; j++)
			cout<<" "<<ans[i][j];
		cout<<endl;
	}

	system("Pause");
}


#include <iostream>
#include <vector>
#include <set>
using namespace std;
int main()
{
	//freopen ("input.txt","r",stdin);
	int n;
	cin >> n;
	cout << 1;
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;
int ns[51] = {0};
struct ty
{
	ty (int _x,int _y,int _id) : x(_x), y(_y), id(_id) {}
	int x,y;
	int id;
	bool operator == (int a)
	{
		return a == id;
	}
};
int main()
{
	//freopen ("input.txt","r",stdin);
	int n;
	cin >> n;
	int s = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> ns[i];
		s += ns[i];
	}

	vector<ty> v;
	for (int i = 0; i < n; i++)
	{
		int m = ns[i];
		for (int j = 0; j < m; j++)
		{
			int a;
			cin >> a;
			v.push_back (ty(i + 1,j + 1,a));
		}
	}
	vector<pair<int,int> > res1,res2;
	for (int i = 1; i <= s; i++)
	{
		int id_ch = -1;
		for (int j = i - 1; j < v.size(); j++)
		{
			if (v[j] == i)
			{
				id_ch = j;
				break;
			}
		}
		if (id_ch + 1 != i)
		{
			res1.push_back (make_pair(v[id_ch].x,v[id_ch].y));
			res2.push_back (make_pair(v[i - 1].x,v[i - 1].y));
			swap(v[id_ch].id,v[i - 1].id);
		}
	}
	cout << res1.size() << endl;
	for (int i = 0; i < res1.size(); i++)
	{
		printf ("%d %d %d %d\n",res1[i].first,res1[i].second,res2[i].first,res2[i].second);
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
#include <functional>
#include <queue>
#include <stack>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
#define SORT(c) sort((c).begin(),(c).end())
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;
typedef double real;

//#pragma comment(linker, "/STACK:64000000")

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("../../Common/in", "r", stdin);
		freopen("../../Common/out", "w", stdout);
#endif
	} else if (k == 2) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else {
		freopen("../../Common/in", "w", stdout);
	}
}
//
const int N = (int)1e2 + 10;
const int M = 50;
int C[M], A[M][M], B[M][M];
int n, s = 0;

int findIJ(int k, int &x, int &y) {
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < C[i]; ++j) {
			if (A[i][j] == k) {
				x = i;
				y = j;
				return 0;
			}
		}
	}
	return 1;
}

void solve() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> C[i];
		s += C[i];
	}
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < M; ++j) {
			A[i][j] = 0;
			B[i][j] = 0;
		}
	}
	int k = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < C[i]; ++j) {
			cin >> A[i][j];
			B[i][j] = k++;
		}
	}
	k = 1;
	vector<pair<pair<int, int>, pair<int, int>>> res;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < C[i]; ++j) {
			int x, y;
			findIJ(k++, x, y);
			if (x == i && y == j) {
				continue;
			}
			res.push_back(make_pair(make_pair(x + 1, y + 1), make_pair(i + 1, j + 1)));
			swap(A[x][y], A[i][j]);
		}
	}
	cout << res.size() << endl;
	for (int i = 0; i < (int)res.size(); ++i) {
		cout << res[i].first.first << " " << res[i].first.second << " " << res[i].second.first << " " << res[i].second.second << endl;
	}
}

void solve2() {
	load(3);
}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000);
#endif
#endif
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <conio.h>
#include <utility>
#include <set>
#include <time.h>
#include <list>
#include <typeinfo>
#include <cstdio>
#include <numeric>
#include <limits>
using namespace std;
#define X first
#define Y second
#define PI 3.1415926535897932384626433832795
#define PI2 PI * 2
#define sqr(x) ((x)*(x))
#define all(n) (n).begin(), (n).end()
typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef pair<float, float> pff;
const int MOD = (int)1e9 + 7;

void load(int k = 1) {
	if (k == 1)	{
#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
#endif
	} else if (k == 2) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else if (k == 3) {
		freopen("in", "w", stdout);
	}
}

const int N = (int)1e3 + 2;
const int M = 3;

void solve() {
	int n, C[M], A[M][M], B[M][M];
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < M; ++j) {
			A[i][j] = M * M + 100;
		}
	}
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> C[i];
	}
	int k = 1;
	pair<int, int> poses[M * M + 10];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < C[i]; ++j) {
			cin >> A[i][j];
			B[i][j] = k;
			poses[k] = make_pair(i, j);
			++k;
		}
	}
	vector<pair<pair<int, int>, pair<int, int>>> res;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < C[i]; ++j) {
			while (A[i][j] != B[i][j]) {
				int newi = poses[A[i][j]].X;
				int newj = poses[A[i][j]].Y;
				res.push_back(make_pair(make_pair(i, j), make_pair(newi, newj)));
				swap(A[i][j], A[newi][newj]);
			}
		}
	}
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); ++i) {
		cout << res[i].X.X << " " << res[i].X.Y << " " << res[i].Y.X << " " << res[i].Y.Y << endl;
	}
}

void solve2() {
	//load(3);
}

#define TIME_CHECK

int main() {
#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c1 = clock();
#endif
#endif

	load();
	solve();

#ifndef ONLINE_JUDGE
#ifdef TIME_CHECK
	double c2 = clock();
	cout << endl << "time: " << (c2 - c1) / (CLOCKS_PER_SEC / 1000) << endl;
#endif
#endif
	return 0;
}


#pragma comment(linker, "/STACK:65777216")
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef long double ld;

const ld EPS = 1e-11;
//const int INF = 2147483647;
const int INF = 2000000000;
const li lINF = 9223372036854775807;
const ld PI = 3.14159265358979323846;

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n, i, j, m[100], a[100][100], b[100][100], i1 = 0, ti, tj;
	vector <pair <int, pair <int, int> > > p;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> m[i];
	for (i = 0; i < n; i++)
		for (j = 0; j < m[i]; j++) {
			cin >> a[i][j];
			p.pb( mp(a[i][j], mp(i, j) ) );
		}
	sort (p.begin(), p.end());
	for (i = 0; i < p.size(); i++) {
		b[p[i].sc.fs][p[i].sc.sc] = i;
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < m[i]; j++) {
			if (p[i1].sc.fs != i || p[i1].sc.sc != j) {
				cout << i+1 << ' ' << j+1 << ' ' << p[i1].sc.fs+1 << ' ' << p[i1].sc.sc+1 << "\n";
				ti = p[i1].sc.fs;
				tj = p[i1].sc.sc;
				p[i1].sc.fs = i;
				p[i1].sc.sc = j;
				p[b[i][j]].sc.fs = ti;
				p[b[i][j]].sc.sc = tj;
				swap(b[i][j], b[ti][tj]);
				i1++;
			}
		}
    return 0;
}


#pragma comment(linker, "/STACK:65777216")
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef long double ld;

const ld EPS = 1e-11;
//const int INF = 2147483647;
const int INF = 2000000000;
const li lINF = 9223372036854775807;
const ld PI = 3.14159265358979323846;

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	vector <pair <pair <int, int>, pair <int, int> > > ans;
	int n, i, j, m[100], a[100][100], b[100][100], i1 = 0, ti, tj;
	vector <pair <int, pair <int, int> > > p;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> m[i];
	for (i = 0; i < n; i++)
		for (j = 0; j < m[i]; j++) {
			cin >> a[i][j];
			p.pb( mp(a[i][j], mp(i, j) ) );
		}
	sort (p.begin(), p.end());
	for (i = 0; i < p.size(); i++) {
		b[p[i].sc.fs][p[i].sc.sc] = i;
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < m[i]; j++) {
			if (p[i1].sc.fs != i || p[i1].sc.sc != j) {
				ans.pb(mp(mp(i+1, j+1),mp(p[i1].sc.fs+1, p[i1].sc.sc+1)));
				ti = p[i1].sc.fs;
				tj = p[i1].sc.sc;
				p[i1].sc.fs = i;
				p[i1].sc.sc = j;
				p[b[i][j]].sc.fs = ti;
				p[b[i][j]].sc.sc = tj;
				swap(b[i][j], b[ti][tj]);
				i1++;
			}
		}
	cout << ans.size() << "\n";
	for (i = 0; i < ans.size(); i++)
		cout << ans[i].fs.fs << ' ' << ans[i].fs.sc << ' ' << ans[i].sc.fs << ' ' << ans[i].sc.sc << "\n";
    return 0;
}


#pragma comment(linker, "/STACK:65777216")
#include <iostream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second

typedef long long li;
typedef long double ld;

const ld EPS = 1e-11;
//const int INF = 2147483647;
const int INF = 2000000000;
const li lINF = 9223372036854775807;
const ld PI = 3.14159265358979323846;

int main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	vector <pair <pair <int, int>, pair <int, int> > > ans;
	int n, i, j, m[100], a[100][100], b[100][100], i1 = 0, ti, tj;
	vector <pair <int, pair <int, int> > > p;
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> m[i];
	for (i = 0; i < n; i++)
		for (j = 0; j < m[i]; j++) {
			cin >> a[i][j];
			p.pb( mp(a[i][j], mp(i, j) ) );
		}
	sort (p.begin(), p.end());
	for (i = 0; i < p.size(); i++) {
		b[p[i].sc.fs][p[i].sc.sc] = i;
	}
	for (i = 0; i < n; i++)
		for (j = 0; j < m[i]; j++) {
			if (p[i1].sc.fs != i || p[i1].sc.sc != j) {
				ans.pb(mp(mp(i+1, j+1),mp(p[i1].sc.fs+1, p[i1].sc.sc+1)));
				ti = p[i1].sc.fs;
				tj = p[i1].sc.sc;
				p[i1].sc.fs = i;
				p[i1].sc.sc = j;
				p[b[i][j]].sc.fs = ti;
				p[b[i][j]].sc.sc = tj;
				swap(b[i][j], b[ti][tj]);
			}
			i1++;
		}
	cout << ans.size() << "\n";
	for (i = 0; i < ans.size(); i++)
		cout << ans[i].fs.fs << ' ' << ans[i].fs.sc << ' ' << ans[i].sc.fs << ' ' << ans[i].sc.sc << "\n";
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
//#include <ctime>

using namespace std;

int main(){
    int n,i,m = 0,j;
    int c[55], rec[55][55],x[2550][2];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<c[i];j++){
            scanf("%d",&rec[i][j]);
            x[rec[i][j]][0] = i;
            x[rec[i][j]][1] = j;
            m = max( m, rec[i][j]);
        }
    }
    int an = 0, ans[2550][4];
    for(i=n-1;i>=0;i--){
        for(j=c[i]-1;j>=0;j--){
            if(m==rec[i][j]){
                m--;
                continue;
            }
            ans[an][0] = x[rec[i][j]][0];
            ans[an][1] = x[rec[i][j]][1];
            ans[an][2] = x[m][0];
            ans[an][3] = x[m][1];

            swap(x[rec[i][j]][0],x[m][0]);
            swap(x[rec[i][j]][1],x[m][1]);

            rec[x[rec[i][j]][0]][x[rec[i][j]][1]]=rec[i][j];
            m--;
            an++;
        }
    }
    printf("%d\n",an);
    for(i=0;i<an;i++){
        for(j=0;j<4;j++)printf("%d ",ans[i][j]+1);
        printf("\n");
    }
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
//#include <ctime>

using namespace std;

int main(){
    int n,i,m = 0,j;
    int c[55], rec[55][55],x[255][2];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<c[i];j++){
            scanf("%d",&rec[i][j]);
            x[rec[i][j]][0] = i;
            x[rec[i][j]][1] = j;
            m = max( m, rec[i][j]);
        }
    }
    int an = 0, ans[255][4];
    for(i=n-1;i>=0;i--){
        for(j=c[i]-1;j>=0;j--){
            if(m==rec[i][j]){
                m--;
                continue;
            }
            ans[an][0] = x[rec[i][j]][0];
            ans[an][1] = x[rec[i][j]][1];
            ans[an][2] = x[m][0];
            ans[an][3] = x[m][1];

            swap(x[rec[i][j]][0],x[m][0]);
            swap(x[rec[i][j]][1],x[m][1]);

            rec[x[rec[i][j]][0]][x[rec[i][j]][1]]=rec[i][j];
            m--;
            an++;
        }
    }
    printf("%d\n",an);
    for(i=0;i<an;i++){
        for(j=0;j<4;j++)printf("%d ",ans[i][j]+1);
        printf("\n");
    }
    return 0;
}
/*
3
3 2 1
4 3 5
6 1
2
*/


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

vector<int> ans1;
vector<int> ans2;
vector<int> ans3;
vector<int> ans4;
int px[3000];
int py[3000];
int k[100];
int a[100][100];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			int t;
			cin>>t;
			px[t]=j;
			py[t]=i;
			a[i][j]=t;
		}
	}

	int cur=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			if(!(px[cur]==j && py[cur]==i)){
				ans1.push_back(px[cur]);
				ans2.push_back(py[cur]);
				ans3.push_back(j);
				ans4.push_back(i);
				px[a[i][j]]=px[cur];
				py[a[i][j]]=py[cur];
				int t=a[i][j];
				a[i][j]=cur;
				a[py[cur]][px[cur]]=t;
			}
			cur++;
		}
	}
	cout<<ans1.size()<<endl;
	for(int i=0;i<ans1.size();i++){
		cout<<ans2[i]<<" "<<ans1[i]<<" "<<ans4[i]<<" "<<ans3[i]<<endl;
	}
#ifndef ONLINE_JUDGE
for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
}
#endif
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

vector<int> ans1;
vector<int> ans2;
vector<int> ans3;
vector<int> ans4;
int px[100];
int py[100];
int k[100];
int a[100][100];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			int t;
			cin>>t;
			px[t]=j;
			py[t]=i;
			a[i][j]=t;
		}
	}

	int cur=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			if(!(px[cur]==j && py[cur]==i)){
				ans1.push_back(px[cur]);
				ans2.push_back(py[cur]);
				ans3.push_back(j);
				ans4.push_back(i);
				px[a[i][j]]=px[cur];
				py[a[i][j]]=py[cur];
				int t=a[i][j];
				a[i][j]=cur;
				a[py[cur]][px[cur]]=t;
			}
			cur++;
		}
	}
	cout<<ans1.size()<<endl;
	for(int i=0;i<ans1.size();i++){
		cout<<ans2[i]<<" "<<ans1[i]<<" "<<ans4[i]<<" "<<ans3[i]<<endl;
	}
#ifndef ONLINE_JUDGE
for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
}
#endif
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

vector<int> ans1;
vector<int> ans2;
vector<int> ans3;
vector<int> ans4;
int px[100];
int py[100];
int k[100];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			int t;
			cin>>t;
			px[t]=j;
			py[t]=i;
		}
	}

	int cur=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			if(!(px[cur]==j && py[cur]==i)){
				ans1.push_back(px[cur]);
				ans2.push_back(py[cur]);
				ans3.push_back(j);
				ans4.push_back(i);
			}
			cur++;
		}
	}
	cout<<ans1.size()<<endl;
	for(int i=0;i<ans1.size();i++){
		cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<" "<<ans4[i]<<endl;
	}
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

vector<int> ans1;
vector<int> ans2;
vector<int> ans3;
vector<int> ans4;
int px[100];
int py[100];
int k[100];
int a[100][100];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			int t;
			cin>>t;
			px[t]=j;
			py[t]=i;
			a[i][j]=t;
		}
	}

	int cur=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			if(!(px[cur]==j && py[cur]==i)){
				ans1.push_back(px[cur]);
				ans2.push_back(py[cur]);
				ans3.push_back(j);
				ans4.push_back(i);
				px[a[i][j]]=px[cur];
				py[a[i][j]]=py[cur];
				//int t=a[i][j];
				//a[i][j]=cur;
				//a[py[cur]][px[cur]]=t;
			}
			cur++;
		}
	}
	cout<<ans1.size()<<endl;
	for(int i=0;i<ans1.size();i++){
		cout<<ans2[i]<<" "<<ans1[i]<<" "<<ans4[i]<<" "<<ans3[i]<<endl;
	}
#ifndef ONLINE_JUDGE
for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			cout<<a[i][j]<<" ";
		}
		cout<<endl;
}
#endif
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;

vector<int> ans1;
vector<int> ans2;
vector<int> ans3;
vector<int> ans4;
int px[100];
int py[100];
int k[100];
int a[100][100];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
	}

	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			int t;
			cin>>t;
			px[t]=j;
			py[t]=i;
			a[i][j]=t;
		}
	}

	int cur=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=k[i];j++){
			if(!(px[cur]==j && py[cur]==i)){
				ans1.push_back(px[cur]);
				ans2.push_back(py[cur]);
				ans3.push_back(j);
				ans4.push_back(i);
				px[a[i][j]]=px[cur];
				py[a[i][j]]=py[cur];
			}
			cur++;
		}
	}
	cout<<ans1.size()<<endl;
	for(int i=0;i<ans1.size();i++){
		cout<<ans1[i]<<" "<<ans2[i]<<" "<<ans3[i]<<" "<<ans4[i]<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

vvi a;
int t = 0;

void LoAd()
{
    int n;
    cin >> n;
    a.resize(n);
    for (int x, i = 0; i < n; i++)
    {
        cin >> x;
        a[i].resize(x);
        t += x;
    }
    for (int i = 0; i < (int) a.size(); i++)
        for (int j = 0; j < (int) a[i].size(); j++)
            cin >> a[i][j];
}

vector<pii> res;
vector<pii> wh;

void SoLvE()
{
    wh.resize(t + 1);

    for (int i = 0; i < (int) a.size(); i++)
    {
        for (int j = 0; j < (int) a[i].size(); j++)
        {
            wh[a[i][j]] = mp(i, j);
        }
    }
    int cur = 1;

    for (int i = 0; i < (int) a.size(); i++)
    {
        for (int j = 0; j < (int) a[i].size(); j++)
        {
            if (cur != a[i][j])
            {
                pii v = wh[cur];
                swap(wh[cur], wh[a[i][j]]);
                swap(a[i][j], a[v.first][v.second]);
                res.push_back(mp(i + 1, j + 1));
                res.push_back(mp(v.first + 1, v.second + 1));
                cur++;
            }
        }

    }
    cout << res.size() / 2 << endl;
    for (int i = 0; i < (int) res.size(); i++)
    {
        printf("%d %d ", res[i].first, res[i].second);
        if (1 == i % 2)
            puts("");
    }

}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);   freopen("output.txt","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <set>
#include <string>
#include <time.h>
#include <vector>

#define nextLine() {for(int c=getchar(); c!='\n' && c!=EOF; c=getchar());}
#define sqr(a) ((a)*(a))
#define has(mask,i) (((mask) & (1<<(i))) == 0 ? false : true)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

#define TASK "file"

using namespace std;

#define pii pair<int,int>
#define mp(x, y) make_pair(x, y)
#define pb(_o_) push_back(_o_)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double ldb;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<int> vb;
typedef vector<vi> vvb;
typedef list<int> li;
typedef multiset<int>::iterator siit;

const int inf = (1 << 30) - 1;
const ldb eps = 1e-9;
const ldb pi = fabs(atan2(0.0, -1.0));

#ifndef ONLINE_JUDGE
#define parr(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";puts("");}puts("");
#else
#define parr(a,n,m) for(int i=0;i<2;i++)i++;
#endif

void ML()
{
    int *ass;
    for (;;)
    {
        ass = new int[2500000];
        for (int i = 0; i < 2500000; i++)
            ass[i] = rand();
    }
}

vvi a;
int t = 0;

void LoAd()
{
    int n;
    cin >> n;
    a.resize(n);
    for (int x, i = 0; i < n; i++)
    {
        cin >> x;
        a[i].resize(x);
        t += x;
    }
    for (int i = 0; i < (int) a.size(); i++)
        for (int j = 0; j < (int) a[i].size(); j++)
            cin >> a[i][j];
}

vector<pii> res;
vector<pii> wh;

void SoLvE()
{
    wh.resize(t + 1);

    for (int i = 0; i < (int) a.size(); i++)
    {
        for (int j = 0; j < (int) a[i].size(); j++)
        {
            wh[a[i][j]] = mp(i, j);
        }
    }
    int cur = 1;

    for (int i = 0; i < (int) a.size(); i++)
    {
        for (int j = 0; j < (int) a[i].size(); j++)
        {
            if (cur != a[i][j])
            {
                pii v = wh[cur];
                swap(wh[cur], wh[a[i][j]]);
                swap(a[i][j], a[v.first][v.second]);
                res.push_back(mp(i + 1, j + 1));
                res.push_back(mp(v.first + 1, v.second + 1));
            }
            cur++;
        }

    }
    cout << res.size() / 2 << endl;
    for (int i = 0; i < (int) res.size(); i++)
    {
        printf("%d %d ", res[i].first, res[i].second);
        if (1 == i % 2)
            puts("");
    }

}

int main()
{
    srand( (int) time(NULL));
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);   freopen("output.txt","w",stdout);
#endif
    LoAd();
    SoLvE();
    return 0;
}


#include<iostream>
#include<vector>
#include<utility>
using namespace std;
int a[51];
int grid[51][51];
vector<int> r1, r2, r3,r4;
pair<int, int> m[3000];
int main()
{
	int n,i,j;
	cin >> n;
	for (int i = 1; i<=n; i++)
		cin >> a[i];
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= a[i]; j++)
		{
			cin >> grid[i][j];
			m[grid[i][j]] = make_pair(i, j);
		}
	}
	int wanted = 1;
	for (i = 1; i <= n; i++)
	{
		for (j = 1;j<= a[i];j++,wanted++)
		{
			int ii = m[wanted].first;
			int jj = m[wanted].second;
			int cur = grid[i][j];
			if (cur == wanted)
				continue;
			m[cur].first = ii;
			m[cur].second = jj;
			grid[i][j] = wanted;
			grid[ii][jj] = cur;
			r1.push_back(i); r2.push_back(j);
			r3.push_back(ii);r4.push_back(jj);
		}
	}
	int l = r1.size();
	cout << l << endl;
	for (i = 0; i < l; i++)
		cout << r1[i] << " " << r2[i] << " " << r3[i] << " " << r4[i] << endl;
	return 0;
}


                            ///************* H.A.N Smile **************///
#include <bits/stdc++.h>
#define f first
#define s second
#define ii pair <int, int>
#define HAN ""
#define pb push_back
#define mp make_pair
#define MOD 1000000009
#define ll long long
#define lli pair <long long , int>
using namespace std;
const int N = 1e5 + 5, M = 1e6 + 5;

int n , t[N], maxx;
bool dd[M];
string ans, s[N] , res;
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen(HAN".inp", "r", stdin);
    //freopen(HAN".out", "w", stdout);
    cin >> n;
    for (int i = 1 ; i <= 1e6 ; ++i) res += 'a';

    for (int i = 1; i <= n; ++i)
    {
        cin >> s[i];
        cin >> t[i];
        for (int j = 1 ; j <= t[i]; ++j)
        {
            int pos;
            cin >> pos;
            --pos;
            int q = s[i].size();
            maxx = max(maxx, pos+q-1);
            for (int p = pos ; p < pos + s[i].size(); ++p){
                res[p] = s[i][p-pos], dd[p] = 1 ;
            }
        }
    }

    for (int i = 0 ; i <= maxx ; ++i) ans += res[i];
    cout <<ans;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb(make_pair(a,i));
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		cout<<ans[i];
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb({a,i});
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		cout<<ans[i];
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb(make_pair(a,i));
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		printf("%c",ans[i]);
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb(make_pair(a,i));
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		printf("%c",ans[i]);
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb(make_pair(a,i));
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		cout<<ans[i];
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb(make_pair(a,i));
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		cout<<ans[i];
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}

ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<int> VI;

int n, k[100005],a;
string s[100005];
VI adj[100005];

char ans[3000006];
int done[2000006],length[2000006];
vector<ii> all;
int main()
{
	ios_base::sync_with_stdio(false);
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s[i]>>k[i];
		length[i] = s[i].length();
		for(int j=0;j<k[i];j++)
		{
			cin>>a;
			adj[i].pb(a);
			all.pb(make_pair(a,i));
		}
	}
	sort(all.begin(),all.end());
	int pos = 1;
	for(int i=0;i<all.size();i++)
	{
		int next = all[i].ff;
		while(pos < next)
		{
			ans[pos] = 'a';
			pos++;
		}
		int len = length[all[i].ss];
		for(int j=pos;j<next+len;j++)
		{
			ans[j] = s[all[i].ss][j-next];
		}
		pos = max(pos,next+len);
	}
	for(int i=1;i<pos;i++)
		cout<<ans[i];
	cout<<"\n";

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, f[3000007], k, mx = 0;
char s[3000007], s1[3000007];
int gf(int x) {
	while (x != f[x])x = f[x] = x[f][f];
	return x;
}
int main() {
	for (int i = 1; i <= 3000000; ++i)f[i] = i;
	for (scanf("%d", &n); n; --n) {
		scanf("%s%d", s1, &k);
		int len = strlen(s1);
		for (int x; k; --k) {
			scanf("%d", &x);
			for (int i = gf(x); i<x + len; i = f[i] = gf(i + 1)) {
				s[i] = s1[i - x];
				if (i>mx)mx = i;
			}
		}
	}
	for (int i = 1; i <= mx; ++i)putchar(s[i] ? s[i] : 'a'); puts("");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
char ans[3000005];
char t[3000005];

int main() {
	scanf("%d", &n);
	int k;
	unsigned long long p, m, len = 0, slen;
	for (int i = 0; i < n; ++i) {
		scanf("%s%d", t, &k);
		slen = strlen(t);
		for (int j = 0; j < k; ++j) {
			scanf("%I64d", &p);
			--p;
			for (m = 0; m < slen; ++m)
				ans[p + m] = t[m];
		}
		len = max(len, p + slen);
	}
	for (int i = 0; i < len; ++i) {
		putchar(ans[i] ? ans[i] : 'a');
	}
	putchar('\n');
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
char ans[3000005];
char t[3000000];

int main() {
	scanf("%d", &n);
	int k;
	unsigned long long p, m, len = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%s%d", t, &k);
		int slen = strlen(t);
		for (int j = 0; j < k; ++j) {
			scanf("%I64d", &p);
			--p;
			for (m = 0; m < slen; ++m)
				ans[p + m] = t[m];
		}
		len = max(len, p + slen);
	}
	for (int i = 0; i < len; ++i) {
		putchar(ans[i] ? ans[i] : 'a');
	}
	putchar('\n');
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int n;
char ans[3000005];
char t[3000000];

int main() {
	scanf("%d", &n);
	int k;
	unsigned long long p, m, len = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%s%d", t, &k);
		int slen = strlen(t);
		for (int j = 0; j < k; ++j) {
			scanf("%I64d", &p);
			--p;
			for (m = 0; m < slen; ++m)
				ans[p + m] = t[m];
		}
		len = max(len, p + slen);
	}
	for (int i = 0; i < len; ++i) {
		putchar(ans[i] ? ans[i] : 'a');
	}
	putchar('\n');
	return 0;
}


int n;
char ans[3000005];
char t[3000000];

int main() {
	scanf("%d", &n);
	int k;
	unsigned long long p, m, len = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%s%d", t, &k);
		int slen = strlen(t);
		for (int j = 0; j < k; ++j) {
			scanf("%I64d", &p);
			--p;
			for (m = 0; m < slen; ++m)
				ans[p + m] = t[m];
		}
		len = max(len, p + slen);
	}
	for (int i = 0; i < len; ++i) {
		putchar(ans[i] ? ans[i] : 'a');
	}
	putchar('\n');
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
char ans[3000005];
char t[3000005];
int f[3000005];

inline int find(int i) {
	while (i != f[i])
		i = f[i] = f[f[i]];
	return i;
}
int main() {
	for (int i = 0; i < 3000005; ++i)
		f[i] = i;
	scanf("%d", &n);
	int k, p, len = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%s%d", t, &k);
		int slen = strlen(t);
		for (int j = 0; j < k; ++j) {
			scanf("%d", &p);
			--p;
			for (int m = find(p); m < p + slen; m = f[m] = find(m + 1))
				ans[m] = t[m - p];
		}
		len = max(len, p + slen);
	}
	for (int i = 0; i < len; ++i)
		putchar(ans[i] ? ans[i] : 'a');
	putchar('\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6+100;
string s[maxn];
vector<pair<int,int> >tmp;
int main(void)
{
    int n,k,x;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>s[i]>>k;
        for(int j=0;j<k;j++)
        {
            scanf("%d",&x);
            tmp.push_back(make_pair(x,i));
        }
    }
    sort(tmp.begin(),tmp.end());
    string ans;
    int len = 1;
    for(unsigned i = 0;i<tmp.size();i++)
    {
        int t1 = tmp[i].first,t2 = tmp[i].second;
        while(t1>len)
        {
            ans += 'a';
            len++;
        }
        //len-t1可以避免重复添加
        for(unsigned j = len-t1;j<s[t2].length();j++)
        {
            ans += s[t2][j];
            len++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						if(pre[i]>=len-j)
						{
							flag=1;
							break;
						}
						int temp=pre[i];
						i=i+temp;
	//					pre[i-temp]=len-j;
						j=i-p;
					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=2e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,temp,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				temp=pre[p];
		//		cout<<temp<<endl;
				if(temp>=len) continue;
				for(i=p+temp,j=temp;i<=p-1+len;i++,j++)
				{
					ans[i]=t[j];
					pre[i]=len-j;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		puts(ans+1);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,temp,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				temp=pre[p];
		//		cout<<temp<<endl;
				if(temp>=len) continue;
				for(i=p+temp,j=temp;i<=p-1+len;i++,j++)
				{
					ans[i]=t[j];
					pre[i]=len-j;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		puts(ans+1);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						if(pre[i]>=len-j)
						{
							flag=1;
							break;
						}
						int temp=pre[i];
						i=i+temp;
						j=i-p-pre[i];
						pre[i-temp]=len-j;
					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						int temp=pre[i];
						i=i+temp;
						pre[i-temp]=len-j;
						j=i-p;
						if(i>p-1+len)
						{
							flag=1;
							break;
						}
					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=2e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,temp,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					if(pre[i]>=len-j) break;
					while(pre[i])
					{
						i=i+pre[i];
						j=i-p-pre[i];
					}
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					if(pre[i]>=len-j) break;
					while(pre[i])
					{
						int temp=pre[i];
						i=i+temp;
						j=i-p-pre[i];
						pre[i-temp]=len-j;
					}
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						int temp=pre[i];
						i=i+temp;
						pre[i-temp]=len-j;
						j=i-p;
						if(i>p-1+len)
						{
							flag=1;
							break;
						}
					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 2 1 12
aba 2 4 6
bc 2 9 13
c 2 14 16
vcg 1 15

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=2e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						int temp=pre[i];
						i=i+temp;
						pre[i-temp]=len-j;
						j=i-p;
						if(i>p-1+len)
						{
							flag=1;
							break;
						}
					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 2 1 12
aba 2 4 6
bc 2 9 13
c 2 14 16
vcg 1 15

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						if(pre[i]>=len-j)
						{
							flag=1;
							break;
						}
						int temp=pre[i];
						i=i+temp;
						pre[i-temp]=len-j;
						j=i-p;
					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,temp,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					if(pre[i]>=len-j) break;
					if(pre[i])
					{
						i=i+pre[i];
						j=p+len-i;
					}
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					int flag=0;
					while(pre[i])
					{
						if(pre[i]>=len-j)
						{
							flag=1;
							break;
						}
						int temp=pre[i];
						i=i+temp;
						j=i-p;
						pre[i-temp]=len-j;

					}
					if(flag) break;
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cctype>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#define mem(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=1e6+10;
const ll mod=1e6;
char ans[MAX],t[MAX];
int pre[MAX];
int main()
{
	int n,i,j,k,p,len,temp,maxx;
	while(~scanf("%d",&n))
	{
		mem(pre,0);
		mem(ans,0);
		maxx=0;
		while(n--)
		{
			scanf("%s%d",t,&k);
			len=strlen(t);
			while(k--)
			{
				scanf("%d",&p);
				maxx=max(maxx,p+len-1);
				for(i=p,j=0;i<=p-1+len;)
				{
					if(pre[i]>=len-j) break;
					while(pre[i])
					{
						i=i+pre[i];
						j=i-p-pre[i];
					}
	//				cout<<i<<" "<<j<<endl;
					ans[i]=t[j];
					pre[i]=len-j;
					i++;
					j++;
				}
			}
		}
		for(i=1;i<=maxx;i++)
		{
			if(ans[i]==0) ans[i]='a';
		}
		ans[maxx+1]='\0';
		puts(ans+1);
	}
	return 0;
}
/*
5
abc 1 1
aba 2 4 6
bc 2 9 14
c 1 17
vcg 1 16

abcabababc  bcvcg
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 8;

int t[N];
string s[N];
int le[N];
char res[N];

int main()
{
    ios::sync_with_stdio(false);
    int n, m = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        int k;
        cin >> k;
        for (int j = 1; j <= k; j++)
        {
            int x;
            cin >> x;
            if (le[x] < s[i].length())
            {
                t[x] = i;
                le[x] = s[i].length();
            }
            m = max(m, x);
        }
    }
    int r = 0;
    for (int i = 1; i <= m + le[m] - 1; i++) res[i] = '*';
    for (int i = 1; i <= m; i++)
    {
        if (t[i] == 0) continue;
        if (i + le[i] - 1 <= r) continue;
        for (int j = max(r + 1, i); j <= i + le[i] - 1; j++) res[j] = s[t[i]][j - i];
        r = i + le[i] - 1;
    }
    for (int i = 1; i <= m + le[m] - 1; i++) if (res[i] == '*') cout << 'a'; else cout << res[i];
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 8;

int t[N];
string s[N];
int le[N];
char res[N];

int main()
{
    ios::sync_with_stdio(false);
    int n, m = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        int k;
        scanf("%d", &k);
        for (int j = 1; j <= k; j++)
        {
            int x;
            scanf("%d", &x);
            if (le[x] < s[i].length())
            {
                t[x] = i;
                le[x] = s[i].length();
            }
            m = max(m, x);
        }
    }
    int r = 0;
    for (int i = 1; i <= m + le[m] - 1; i++) res[i] = '*';
    for (int i = 1; i <= m; i++)
    {
        if (t[i] == 0) continue;
        if (i + le[i] - 1 <= r) continue;
        for (int j = max(r + 1, i); j <= i + le[i] - 1; j++) res[j] = s[t[i]][j - i];
    }
    for (int i = 1; i <= m + le[m] - 1; i++) if (res[i] == '*') cout << 'a'; else cout << res[i];
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 8;

int t[N];
string s[N];
int le[N];
char res[N];

int main()
{
    ios::sync_with_stdio(false);
    int n, m = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        int k;
        cin >> k;
        for (int j = 1; j <= k; j++)
        {
            int x;
            cin >> x;
            if (le[x] < s[i].length())
            {
                t[x] = i;
                le[x] = s[i].length();
            }
            m = max(m, x);
        }
    }
    int r = 0;
    for (int i = 1; i <= m + le[m] - 1; i++) res[i] = '*';
    for (int i = 1; i <= m; i++)
    {
        if (t[i] == 0) continue;
        if (i + le[i] - 1 <= r) continue;
        for (int j = max(r + 1, i); j <= i + le[i] - 1; j++) res[j] = s[t[i]][j - i];
    }
    for (int i = 1; i <= m + le[m] - 1; i++) if (res[i] == '*') cout << 'a'; else cout << res[i];
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 8;

int t[N];
string s[N];
int le[N];
char res[N];

int main()
{
    int n, m = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        int k;
        cin >> k;
        for (int j = 1; j <= k; j++)
        {
            int x;
            cin >> x;
            if (le[x] < s[i].length())
            {
                t[x] = i;
                le[x] = s[i].length();
            }
            m = max(m, x);
        }
    }
    int r = 0;
    for (int i = 1; i <= m + le[m] - 1; i++) res[i] = '*';
    for (int i = 1; i <= m; i++)
    {
        if (t[i] == 0) continue;
        if (i + le[i] - 1 <= r) continue;
        for (int j = max(r + 1, i); j <= i + le[i] - 1; j++) res[j] = s[t[i]][j - i];
    }
    for (int i = 1; i <= m + le[m] - 1; i++) if (res[i] == '*') cout << 'a'; else cout << res[i];
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e6 + 8;

int t[N];
string s[N];
int le[N];
char res[N];

int main()
{
    ios::sync_with_stdio(false);
    int n, m = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        int k;
        cin >> k;
        for (int j = 1; j <= k; j++)
        {
            int x;
            cin >> x;
            if (le[x] < s[i].length())
            {
                t[x] = i;
                le[x] = s[i].length();
            }
            m = max(m, x + le[x] - 1);
        }
    }
    int r = 0;
    for (int i = 1; i <= m + le[m] - 1; i++) res[i] = 'a';
    for (int i = 1; i <= m; i++)
    {
        if (t[i] == 0) continue;
        if (i + le[i] - 1 <= r) continue;
        for (int j = max(r + 1, i); j <= i + le[i] - 1; j++) res[j] = s[t[i]][j - i];
        r = i + le[i] - 1;
    }
    for (int i = 1; i <= m; i++) cout << res[i];
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char s[10000050],t[1000050];
int vis[2000500];
int main()
{
	int n,k,x,maxx=-1;
	scanf("%d",&n);
	for(int i=1;i<=200050;i++)
		vis[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",t);
		int tt=strlen(t);
		scanf("%d",&k);
		for(int j=1;j<=k;j++)
		{
			scanf("%d",&x);
			for(int r=vis[x];r<=tt+x-1;r=vis[r])
			{
				s[r]=t[r-x];
				vis[r]=r+1;
			}
			if(maxx<tt+x-1)
				maxx=tt+x-1;
		}
	}
	for(int i=1;i<=maxx;i++)
	{
		if(s[i]=='\0')
			s[i]='a';
	}
	printf("%s\n",s+1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char s[3000050],t[3000050];
int vis[3000500];
int find(int a)
{
	int r=a;
	while(vis[r]!=r)
	r=vis[r];
	int i=a;
	int j;
	while(i!=r)
	{
		j=vis[i];
		vis[i]=r;
		i=j;
	}
	return r;
}
void merge(int a,int b)
{
	int aa=find(a);
	int bb=find(b);
	if(aa>bb)
		vis[bb]=aa;
	else
		vis[aa]=bb;
	return ;
}
int main()
{
	int n,k,x,maxx=-1;
	scanf("%d",&n);
	for(int i=0;i<3000500;i++)
		vis[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",t);
		int tt=strlen(t);
		scanf("%d",&k);
		for(int j=1;j<=k;j++)
		{
			scanf("%d",&x);
			int tmpx=x;
/*			for(int r=vis[x];r<=tt+x-1;r=vis[r])
			{
				s[r]=t[r-x];
				vis[r]=vis[r+1];
			}
			for(int r=vis[x];r<=tt+x-1;r=vis[r])
			{
				vis[r]=vis[tt+x-1];
			}*/
			while(x<=tt+tmpx-1)
			{
				s[x]=t[x-tmpx];
				x=find(x);
				if(x<=tmpx+tt-1) merge(x,x+1);
			}
			if(maxx<tt+x-1)
				maxx=tt+tmpx-1;
		}
	}
	for(int i=1;i<=maxx;i++)
	{
		if(s[i]=='\0')
			s[i]='a';
		printf("%c",s[i]);
	}
	printf("\n");
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char s[10000050],t[1000050];
int vis[2000500];
int main()
{
	int n,k,x,maxx=-1;
	scanf("%d",&n);
	for(int i=1;i<2000500;i++)
		vis[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",t);
		int tt=strlen(t);
		scanf("%d",&k);
		for(int j=1;j<=k;j++)
		{
			scanf("%d",&x);
			for(int r=vis[x];r<=tt+x-1;r=vis[r])
			{
				s[r]=t[r-x];
				vis[r]=vis[r+1];
			}
			for(int r=vis[x];r<=tt+x-1;r=vis[r])
			{
				vis[r]=tt+x;
			}
			if(maxx<tt+x-1)
				maxx=tt+x-1;
		}
	}
	for(int i=1;i<=maxx;i++)
	{
		if(s[i]=='\0')
			s[i]='a';
	}
	printf("%s\n",s+1);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char s[10000050],t[1000050];
int vis[2000500];
int main()
{
	int n,k,x,maxx=-1;
	scanf("%d",&n);
	for(int i=1;i<2000500;i++)
		vis[i]=i;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",t);
		int tt=strlen(t);
		scanf("%d",&k);
		for(int j=1;j<=k;j++)
		{
			scanf("%d",&x);
			for(int r=vis[x];r<=tt+x-1;r=vis[r])
			{
				s[r]=t[r-x];
				vis[r]=r+1;
			}
			if(maxx<tt+x-1)
				maxx=tt+x-1;
		}
	}
	for(int i=1;i<=maxx;i++)
	{
		if(s[i]=='\0')
			s[i]='a';
	}
	printf("%s\n",s+1);
	return 0;
}