/*
KMP s[k....j]==s[m....i]（两个字符串完全相等）
char s[10005];
int next[10005];

int get_next(int len)
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])//j>=0
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return next[len-1];
}
  */

#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
        int ans=0;
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            if(!flag)
            {
                int g1=len_s/c1 ,g2=len_t/c2;
                for(i=1;i<=g1 && i<=g2;i++)
                    if(g1%i==0 && g2%i==0)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else
        {
            if(len_s%len_t==0)
            {
                for(i=0;i<len_s;i++)
                    if(s[i]!=t[i%len_t])
                        break;
                if(i>=len_s) ans++;
            }
            else if(len_t%len_s==0)
            {
                for(i=0;i<len_t;i++)
                    if(t[i]!=s[i%len_s])
                        break;
                if(i>=len_t) ans++;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
//  printf("%d  %d  gao\n",len,next[len-1]);
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
        int ans=0;
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            if(!flag)
            {
                int g1=len_s/c1 ,g2=len_t/c2;
                for(i=1;i<=g1 && i<=g2;i++)
                    if(g1%i==0 && g2%i==0)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else
        {
        //  puts("ffff");
            if(len_s%len_t==0)
            {
                for(i=0;i<len_s;i++)
                    if(s[i]!=s[i%len_t])
                        break;
                if(i>=len_s) ans++;
            }
            else if(len_t%len_s==0)
            {
                for(i=0;i<len_t;i++)
                    if(s[i]!=s[i%len_s])
                        break;
                if(i>=len_t) ans++;
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
    //  printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
                //printf("%d\n",i);
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            int ans=0;
            int g1=len_s/c1 ,g2=len_t/c2;
            for(i=1;i<=g1 && i<=g2;i++)
                if(g1%i==0 && g2%i==0)
                {
                    ans++;
                }
            if(!flag)
                printf("%d\n",ans);
            else
                puts("0");

        }
        else  puts("0");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
    //  printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            int ans=0;
            int g1=len_s/c1 ,g2=len_t/c2;
        //  printf("%d %d",g1,g2);
            for(i=1;i<=g1 && i<=g2;i++)
                if(g1%i==0 && g2%i==0)
                {
                    ans++;
                }
            if(!flag)
                printf("%d\n",ans);

        }
        else if(flag)puts("0");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
    //  printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            int ans=0;
            int g1=len_s/c1 ,g2=len_t/c2;
        //  printf("%d %d",g1,g2);
            for(i=1;i<=g1 && i<=g2;i++)
                if(g1%i==0 && g2%i==0)
                {
                    ans++;
                }
            if(!flag)
                printf("%d\n",ans);

        }
        else if puts("0");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
    //  printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            int ans=0;
            int g1=len_s/c1 ,g2=len_t/c2;
        //  printf("%d %d",g1,g2);
            for(i=1;i<=g1 && i<=g2;i++)
                if(g1%i==0 && g2%i==0)
                {
                    ans++;
                }
            if(!flag)
                printf("%d\n",ans);

        }
        else  puts("0");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
//  printf("%d  %d  gao\n",len,next[len-1]);
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
        int ans=0;
        if(len_s%len_t==0)
        {
            for(i=0;i<len_s;i++)
                if(s[i]!=s[i%len_t])
                    break;
            if(i<len_s) ans++;
        }
        else if(len_t%len_s==0)
        {
            for(i=0;i<len_t;i++)
                if(s[i]!=s[i%len_s])
                    break;
            if(i<len_t) ans++;
        }
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            if(!flag)
            {
                int g1=len_s/c1 ,g2=len_t/c2;
                for(i=1;i<=g1 && i<=g2;i++)
                    if(g1%i==0 && g2%i==0)
                        ans++;
            }
            printf("%d\n",ans);
        }
        else  printf("%d\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
    int i=0,j=-1;
    next[0]=-1;
    for(i=1;i<len;i++)
    {
        while(j>=0 && s[j+1]!=s[i])
            j=next[j];
        if(s[j+1]==s[i])
            j++;
        next[i]=j;

    }
    return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main()
{
    int i,j;
    int flag;
    int c1,c2;
    while(scanf("%s%s",s,t)!=EOF)
    {
        len_s=strlen(s);
        len_t=strlen(t);
        c1=get_next(len_s,s,next1);
        c2=get_next(len_t,t,next2);
    //  printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
        flag=0;
        if(c1==c2)
        {
            for(i=0;i<c1;i++)
                if(s[i]!=t[i])
                    break;
            if(i<c1)flag=1;
            if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
            int ans=0;
            int g1=len_s/c1 ,g2=len_t/c2;
        //  printf("%d %d",g1,g2);
            for(i=1;i<=g1 && i<=g2;i++)
                if(g1%i==0 && g2%i==0)
                {
                    ans++;
                }
            if(!flag)
                printf("%d\n",ans);
            else
                puts("1");

        }
        else  puts("0");
    }
    return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
	int i=0,j=-1;
	next[0]=-1;
	for(i=1;i<len;i++)
	{
		while(j>=0 && s[j+1]!=s[i])
			j=next[j];
		if(s[j+1]==s[i])
			j++;
		next[i]=j;

	}
	return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
	return !b?a:gcd(b,a%b);
}

int main()
{
	int i,j;
	int flag;
	int c1,c2;
	while(scanf("%s%s",s,t)!=EOF)
	{
		len_s=strlen(s);
		len_t=strlen(t);
		c1=get_next(len_s,s,next1);
		c2=get_next(len_t,t,next2);
	//	printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
		flag=0;
		if(c1==c2)
		{
			for(i=0;i<c1;i++)
				if(s[i]!=t[i])
					break;
			if(i<c1)flag=1;
			if(len_s%c1!=0 ||len_t%c1!=0) flag=1;
			int ans=0;
			int g1=len_s/c1 ,g2=len_t/c2;
		//	printf("%d %d",g1,g2);
			for(i=1;i<=g1 && i<=g2;i++)
				if(g1%i==0 && g2%i==0)
				{
					ans++;
				}
			if(!flag)
				printf("%d\n",ans);

		}
		if(flag)puts("0");
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
typedef __int64 lld;

void build_next(int len_t,char T[],int next[])
{
	int k, q, p, a;
	next[0] = len_t;
	for (k = 1, q = -1; k < len_t; k ++, q--) {
		if (q < 0 || k + next[k - a] >= p) {
			if (q < 0)q = 0, p = k;
			while (p < len_t && T[p] == T[q]) {
				p ++, q ++;
			}
			next[k] = q, a = k;
		}
		else {
			next[k] = next[k - a];
		}
	}
}

int len_s,len_t;
char T[100005];
char S[100005];
int next1[100005];
int next2[100005];

int main()
{
	int i,j;
	while(scanf("%s%s",T,S)!=EOF)
	{
		len_s=strlen(S);
		len_t=strlen(T);
		build_next(len_s,S,next1);
		build_next(len_t,T,next2);
		int ans=0;
		next1[len_s]=next2[len_t]=0;
		for(i=1;S[i-1]==T[i-1] && i<=len_s && i<=len_t;i++)
		{
			if(len_s%i==0 && len_t%i==0 && next1[i]==len_s-i && next2[i]==len_t-i)
				ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>

int get_next(int len,char s[],int next[])
{
	int i=0,j=-1;
	next[0]=-1;
	for(i=1;i<len;i++)
	{
		while(j>=0 && s[j+1]!=s[i])
			j=next[j];
		if(s[j+1]==s[i])
			j++;
		next[i]=j;

	}
	return len-next[len-1]-1;
}

char s[100005];
char t[100005];
int len_s,len_t;
int next1[100005],next2[100005];

int gcd(int a,int b)
{
	return !b?a:gcd(b,a%b);
}

int main()
{
	int i,j;
	int flag;
	int c1,c2;
	while(scanf("%s%s",s,t)!=EOF)
	{
		len_s=strlen(s);
		len_t=strlen(t);
		c1=get_next(len_s,s,next1);
		c2=get_next(len_t,t,next2);
	//	printf("%d  %d  %d  %d\n",len_s,len_t,c1,c2);
		flag=0;
		if(c1==c2)
		{
			for(i=0;i<=c1;i++)
				if(s[i]!=t[i])
					break;
			if(i<=c1)flag=1;
			if(len_s%(c1)!=0 ||len_t%(c1)!=0) flag=1;

			if(!flag)
				printf("%d\n",gcd(len_s/c1,len_t/c2));

		}
		if(flag)puts("0");
	}
	return 0;
}


#include<cstdio>
#include<cstring>

char a[100050];
char b[100050];
int p[100050];
int m,n;
int l1,l2;

void getp(char b[],int m){
    p[1]=0;
    int i,j=0;
    for(i=2;i<=m;i++){
        while(j>0&&b[j+1]!=b[i]) j=p[j];
        if(b[j+1]==b[i]) j+=1;
        p[i]=j;
    }
}

int Min(int a,int b)
{
    if(a<b) return a;
    return b;
}

int gcd(int a,int b)
{
    return !b?a:gcd(b,a%b);
}

int main(){
    int x1,x2;
    int i;
   while(scanf("%s%s",a+1,b+1)!=EOF)
   {
       m=l1=strlen(a+1);
       getp(a,l1);
       if(m%(m-p[m])==0) x1=m/(m-p[m]);
       else x1=1;
       m=l2=strlen(b+1);
       getp(b,l2);
       if(m%(m-p[m])==0) x2=m/(m-p[m]);
       else x2=1;
      // printf("%d  %d\n",x1,x2);
       if(l1/x1==l2/x2)
       {
        int t=Min(l1/x1,l2/x2);
            for(i=1;i<=t;i++)
                if(a[i]!=b[i])
                    break;
            //printf("%d %d\n",i,t);
            if(i<=t)
                puts("0");
            else
            {
                int ans=gcd(x1,x2);
                printf("%d\n",ans);
            }
       }
       else
           puts("0");

   }
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    //ios_base::sync_with_stdio(0);

    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.size() >= tem2.size()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.size(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[k - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.size(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[k - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.size() % (s.size() -  arr[s.size() - 1] ) != 0 ) {cout << "0\n"; return 0;}
    else len1 = s.size() / (s.size() -  arr[s.size() - 1] );
    if( c.size() % (c.size() -  arr2[c.size() - 1] ) != 0 ) { cout << "0" ; return 0;}
    else len2 = c.size() / (c.size() -  arr2[c.size() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < s.size(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr2[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.size()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    int f = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == c[0]){
            int j;
            bool here = false;
            for(j = 1; j < c.size(); j++){
                if(c[j] != s[i + 1]){
                    here = true;
                }
                i++;
            }
            if(!here) f++;
        }
    }

    if(f * c.size() != s.size() ){

        if(fi){cout << "0"; return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    //ios_base::sync_with_stdio(0);

    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.size() >= tem2.size()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.size(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[k - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.size(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[k - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.size() % (s.size() -  arr[s.size() - 1] ) != 0 ) {len1 = 1;}
    else len1 = s.size() / (s.size() -  arr[s.size() - 1] );
    if( c.size() % (c.size() -  arr2[c.size() - 1] ) != 0 ) { len2 = 1 ;}
    else len2 = c.size() / (c.size() -  arr2[c.size() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < s.size(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr2[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.size()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    int f = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == c[0]){
            int j;
            bool here = false;
            for(j = 1; j < c.size(); j++){
                if(c[j] != s[i + 1]){
                    here = true;
                }
                i++;
            }
            if(!here) f++;
        }
    }

    if(f * c.size() != s.size() ){

        if(fi){cout << "0"; return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n , m , k , d;
    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.length() >= tem2.length()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.length(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[i - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.length(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[i - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.length() % (s.length() -  arr[s.length() - 1] ) != 0 ) {printf("0"); return 0;}
    else len1 = s.length() / (s.length() -  arr[s.length() - 1] );
    if( c.length() % (c.length() -  arr2[c.length() - 1] ) != 0 ) {printf("0"); return 0;}
    else len2 = c.length() / (c.length() -  arr2[c.length() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < s.length(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.length()){
            found = true;
            break;
        }
    }
    if(!found) {printf("0"); return 0;}
    if(s.length() % c.length() != 0){

        if(fi){printf("0"); return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    printf("%d", num);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    ios_base::sync_with_stdio(0);
    int n , m , k , d;
    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.size() >= tem2.size()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.size(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[i - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.size(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[i - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.size() % (s.size() -  arr[s.size() - 1] ) != 0 ) {cout << "0\n"; return 0;}
    else len1 = s.size() / (s.size() -  arr[s.size() - 1] );
    if( c.size() % (c.size() -  arr2[c.size() - 1] ) != 0 ) { cout << "0" ; return 0;}
    else len2 = c.size() / (c.size() -  arr2[c.size() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < c.size(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr2[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.size()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    if(s.size() % c.size() != 0){

        if(fi){cout << "0"; return 0;}
    }

    long long e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(long long i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    ios_base::sync_with_stdio(0);
    int n , m , k , d;
    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.length() >= tem2.length()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.length(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[i - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.length(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[i - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.length() % (s.length() -  arr[s.length() - 1] ) != 0 ) {cout << "0\n"; return 0;}
    else len1 = s.length() / (s.length() -  arr[s.length() - 1] );
    if( c.length() % (c.length() -  arr2[c.length() - 1] ) != 0 ) { cout << "0" ; return 0;}
    else len2 = c.length() / (c.length() -  arr2[c.length() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < s.length(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.length()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    if(s.length() % c.length() != 0){

        if(fi){cout << "0"; return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    ios_base::sync_with_stdio(0);

    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.size() >= tem2.size()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.size(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[k - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.size(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[k - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.size() % (s.size() -  arr[s.size() - 1] ) != 0 ) {cout << "0\n"; return 0;}
    else len1 = s.size() / (s.size() -  arr[s.size() - 1] );
    if( c.size() % (c.size() -  arr2[c.size() - 1] ) != 0 ) { cout << "0" ; return 0;}
    else len2 = c.size() / (c.size() -  arr2[c.size() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < c.size(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr2[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.size()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    if(s.size() % c.size() != 0){

        if(fi){cout << "0"; return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    ios_base::sync_with_stdio(0);
    int n , m , k , d;
    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.length() >= tem2.length()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.length(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[i - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.length(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[i - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.length() % (s.length() -  arr[s.length() - 1] ) != 0 ) {cout << "0\n"; return 0;}
    else len1 = s.length() / (s.length() -  arr[s.length() - 1] );
    if( c.length() % (c.length() -  arr2[c.length() - 1] ) != 0 ) { cout << "0" ; return 0;}
    else len2 = c.length() / (c.length() -  arr2[c.length() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < c.length(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr2[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.length()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    if(s.length() % c.length() != 0){

        if(fi){cout << "0"; return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int arr [100000 + 10];
int arr2 [100000 + 10];

int main()
{
    ios_base::sync_with_stdio(0);
    int n , m , k , d;
    string s , c , tem1 , tem2;
    cin >> tem1 >> tem2;
    bool fi = false;

    if(tem1.size() >= tem2.size()){
        s = tem1;
        c = tem2;
    } else {
        s = tem2;
        c = tem1;
    }
    char r = s[0];
    for(int i = 1, k = 0; i < s.size(); i++){
        while(k > 0 && s[i] != s[k]) k = arr[i - 1];
        if(s[i] == s[k]) k++;
        arr[i] = k;
        if(s[i] != r) fi = true;
    }
    for(int i = 1, k = 0; i < c.size(); i++){
        while(k > 0 && c[i] != c[k]) k = arr2[i - 1];
        if(c[i] == c[k]) k++;
        arr2[i] = k;
        if(c[i] != r) fi = true;
    }
    int len1 , len2;
    if( s.size() % (s.size() -  arr[s.size() - 1] ) != 0 ) {cout << "0\n"; return 0;}
    else len1 = s.size() / (s.size() -  arr[s.size() - 1] );
    if( c.size() % (c.size() -  arr2[c.size() - 1] ) != 0 ) { cout << "0" ; return 0;}
    else len2 = c.size() / (c.size() -  arr2[c.size() - 1] );

    bool found = false;
    for(int i = 0 , k = 0; i < c.size(); i++){
        while( k > 0 && s[i] != c[k]  ) k = arr2[k - 1];
        if(s[i] == c[k]) k++;
        if(k == c.size()){
            found = true;
            break;
        }
    }
    if(!found) {cout << "0"; return 0;}
    if(s.size() % c.size() != 0){

        if(fi){cout << "0"; return 0;}
    }

    int e = __gcd( len1 , len2 );
    int num = 2;
    if(e == 1) num = 1;

    for(int i = 2; i * i <= e; i++){
        if(e % i == 0 && i * i == e   ) num++;
        else if (e % i == 0) num += 2;
    }
    cout << num;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#include <fstream>
#include <ctime>
#include <climits>
using namespace std;
int fail[100005], fail2[100005];
void ZFunction(string s) {
	int l = 0, r = 0;
	for (int i = 1; i < s.length(); ++i)
		if (fail[i - l] <= r - i)
			fail[i] = fail[i - l];
		else
		{
			l = i;
			if (i > r)
				r = i;
			for (fail[i] = r - i; r < s.length(); ++r, ++fail[i])
				if (s[r] != s[fail[i]])
					break;
			--r;
		}
}
void ZFunction2(string s) {
	int l = 0, r = 0;
	for (int i = 1; i < s.length(); ++i)
		if (fail2[i - l] <= r - i)
			fail2[i] = fail2[i - l];
		else
		{
			l = i;
			if (i > r)
				r = i;
			for (fail2[i] = r - i; r < s.length(); ++r, ++fail2[i])
				if (s[r] != s[fail2[i]])
					break;
			--r;
		}
}
int main() {
	string s1, s2; cin >> s1 >> s2;
	if (s2.size() > s1.size()) swap(s1, s2);
	int ans = 0, i;
	ZFunction(s1);
	bool b = false;
	for (i = 1; i < s1.size(); ++i) {
		if (fail[i] == s1.size() - i) {
			b = true;
			for (int j = i + i; j < s1.size(); j += i) {
				if (fail[j] != s1.size() - j) b = false;
			}
			if (b) break;
		}
		b = false;
	}
	if (!b) { cout << "0" << endl; return 0; }
	ZFunction2(s2);
	for (int j = i; j < s2.size(); j += i) {
		if (fail[j] != s1.size() - j) b = false;
	}
	if (!b)  { cout << "0" << endl; return 0; }
	int cnt = 0;
	for (int j = i; j <= s2.size(); j += i)
		if (s1.size() % j == 0 && s2.size() % j == 0) ++cnt;
	cout << cnt << endl;
}


#pragma comment(linker,"/STACK:300000000")
#define _CRT_SECURE_NO_WARNINGS
#pragma warning(disable:4800)

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <memory.h>
#include <cstdio>
#include <sstream>
#include <deque>
#include <bitset>
#include <numeric>
#include <ctime>
#include <queue>
#include <hash_map>

using namespace std;
using namespace stdext;

#define show(x) cout << #x << " = " << (x) << endl;
void showTime() { cerr << (double)clock()/CLOCKS_PER_SEC << endl; }
#define fori(i,n) for(int i = 0; i < (n); i++)
#define forab(i,a,b) for(int i = (a); i <= (b); i++)
#define sz(v) int((v).size())
#define all(v) (v).begin(),(v).end()
const double pi = 3.1415926535897932384626433832795;
template<class T> T abs(const T &a) { return a >= 0 ? a : -a; };
template<class T> T sqr(const T &x) { return x * x; }
typedef pair<int,int> ii;
typedef long long ll;
///////////////////////////////////////

vector<vector<int> > a;
vector<int> c;

int n;

vector<int> fromx, fromy, tox, toy;

void work(int need, int x, int y)
{
	int I, J;
	fori(i,n)
		fori(j,c[i])
			if(a[i][j] == need)
			{
				I = i;
				J = j;
			}
	if(x == I && y == J)
		return;
	fromx.push_back(I);
	fromy.push_back(J);
	tox.push_back(x);
	toy.push_back(y);
}

int main()
{
#ifdef TEDDY_BEARS
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#else
	//freopen(FILENAME".in","r",stdin);
    //freopen(FILENAME".out","w",stdout);
#endif
	cin >> n;
	c.resize(n);
	a.resize(n);
	fori(i,n)
		cin >> c[i];
	fori(i,n)
	{
		a[i].resize(c[i]);
		fori(j,c[i])
		{
			cin >> a[i][j];
			a[i][j]--;
		}
	}
	int cur = 0;
	fori(i,n)
		fori(j,c[i])
		{
			work(cur,i,j);
			cur++;
		}
	/*reverse(all(fromx));
	reverse(all(fromy));
	reverse(all(tox));
	reverse(all(toy));*/
	cout << sz(fromx) << endl;
	fori(i,sz(fromx))
		cout << fromx[i]+1 << ' ' << fromy[i]+1 << ' ' <<
				tox[i]+1 << ' ' << toy[i]+1 << endl;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

#define MAXN 1000
#define INF 1000000000
int c[MAXN];
int a[MAXN][MAXN];
pair < int, int > ind[MAXN];
void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}
int main() {

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &c[i]);
    vector < int > b;
    int s = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            scanf("%d", &a[i][j]);
            b.push_back(a[i][j]);
            ind[a[i][j]] = make_pair(i, j);
            s = max(s, a[i][j]);
        }
    }
    vector < pair < pair < int, int >, pair < int, int > > > ans;
    sort(b.begin(), b.end());
    for (int i = n - 1; i >= 0; i--) {
        for (int j = c[i] - 1; j >= 0; j--)
            if (a[i][j] == s) {
                s--;
                continue;
            } else {
                pair < int, int > p1 = ind[s];
                ans.push_back(make_pair(make_pair(p1.first + 1, p1.second + 1), make_pair(i + 1, j + 1)));
                s--;
                ind[a[i][j]] = ind[s];
                swap(a[p1.first][p1.second], a[i][j]);
            }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

#define MAXN 1000
#define INF 1000000000
int c[MAXN];
int a[MAXN][MAXN];
pair < int, int > ind[MAXN * 10];
void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}
int main() {

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    scanf("%d", &n);
    int s = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        s += c[i];
    }

    vector < int > b;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            scanf("%d", &a[i][j]);
            b.push_back(a[i][j]);
            ind[a[i][j]] = make_pair(i, j);
        }
    }
    vector < pair < pair < int, int >, pair < int, int > > > ans;
    sort(b.begin(), b.end());
    for (int i = n - 1; i >= 0; i--) {
        for (int j = c[i] - 1; j >= 0; j--) {
            s = b.back();
            b.pop_back();
            if (a[i][j] == s) {

                continue;
            } else {
                pair < int, int > p1 = ind[s];
                ans.push_back(make_pair(make_pair(p1.first + 1, p1.second + 1), make_pair(i + 1, j + 1)));

                ind[a[i][j]] = ind[s];
                swap(a[p1.first][p1.second], a[i][j]);
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

#define MAXN 1000
#define INF 1000000000
int c[MAXN];
int a[MAXN][MAXN];
pair < int, int > ind[MAXN];
void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}
int main() {

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    scanf("%d", &n);
    int s = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        s += c[i];
    }

    vector < int > b;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            scanf("%d", &a[i][j]);
            b.push_back(a[i][j]);
            ind[a[i][j]] = make_pair(i, j);
            s = max(s, a[i][j]);
        }
    }
    vector < pair < pair < int, int >, pair < int, int > > > ans;
    sort(b.begin(), b.end());
    for (int i = n - 1; i >= 0; i--) {
        for (int j = c[i] - 1; j >= 0; j--) {
            s = b.back();
            b.pop_back();
            if (a[i][j] == s) {

                continue;
            } else {
                pair < int, int > p1 = ind[s];
                ans.push_back(make_pair(make_pair(p1.first + 1, p1.second + 1), make_pair(i + 1, j + 1)));

                ind[a[i][j]] = ind[s];
                swap(a[p1.first][p1.second], a[i][j]);
            }
        }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    return 0;

}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

#define MAXN 1000
#define INF 1000000000
int c[MAXN];
int a[MAXN][MAXN];
pair < int, int > ind[MAXN];
void swap(int &a, int &b) {
    int tmp = a;
    a = b;
    b = tmp;
}
int main() {

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    scanf("%d", &n);
    int s = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &c[i]);
        s += c[i];
    }

    vector < int > b;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < c[i]; j++) {
            scanf("%d", &a[i][j]);
            b.push_back(a[i][j]);
            ind[a[i][j]] = make_pair(i, j);
            s = max(s, a[i][j]);
        }
    }
    vector < pair < pair < int, int >, pair < int, int > > > ans;
    sort(b.begin(), b.end());
    for (int i = n - 1; i >= 0; i--) {
        s = b.back();
        b.pop_back();
        for (int j = c[i] - 1; j >= 0; j--)
            if (a[i][j] == s) {
                s--;
                continue;
            } else {
                pair < int, int > p1 = ind[s];
                ans.push_back(make_pair(make_pair(p1.first + 1, p1.second + 1), make_pair(i + 1, j + 1)));
                s--;
                ind[a[i][j]] = ind[s];
                swap(a[p1.first][p1.second], a[i][j]);
            }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
        cout << ans[i].first.first << " " << ans[i].first.second << " " << ans[i].second.first << " " << ans[i].second.second << endl;
    return 0;

}


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

#define N 55

int lcm[N][N],c[N];
struct node
{
	int x,y,p,q;
}ans[N * N];
struct nd
{
	int px,py;
}num[N];

int main()
{
	int i,j,ansnum,n;
	while(scanf("%d",&n) != EOF)
	{
		memset(lcm,0,sizeof(lcm));
		for(i = 1;i <= n;i ++)
			scanf("%d",&c[i]);
		for(i = 1;i <= n;i ++)
			for(j = 1;j <= c[i];j ++)
			{
				scanf("%d",&lcm[i][j]);
				num[lcm[i][j]].px = i;
				num[lcm[i][j]].py = j;
			}
		int tmp = 1;
		ansnum = 0;
		for(i = 1;i <= n;i ++)
		{
			for(j = 1;j <= c[i];j ++)
			{
				if(lcm[i][j] != tmp)
				{
					ansnum ++;
					ans[ansnum].x = i;
					ans[ansnum].y = j;
					int ttp = lcm[i][j];
					ans[ansnum].p = num[tmp].px;
					ans[ansnum].q = num[tmp].py;
					lcm[i][j] = tmp;
					lcm[num[tmp].px][num[tmp].py] = ttp;

				}
				tmp ++;
			}
		}
		printf("%d\n",ansnum);
		for(i = 1;i <= ansnum;i ++)
			printf("%d %d %d %d\n",ans[i].x,ans[i].y,ans[i].p,ans[i].q);
	}
	return 0;
}


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

#define N 55

int lcm[N][N],c[N];
struct node
{
	int x,y,p,q;
}ans[N * N];
struct nd
{
	int px,py;
}num[N];

int main()
{
	int i,j,ansnum,n;
	while(scanf("%d",&n) != EOF)
	{
		memset(lcm,0,sizeof(lcm));
		for(i = 1;i <= n;i ++)
			scanf("%d",&c[i]);
		for(i = 1;i <= n;i ++)
			for(j = 1;j <= c[i];j ++)
			{
				scanf("%d",&lcm[i][j]);
				num[lcm[i][j]].px = i;
				num[lcm[i][j]].py = j;
			}
		int tmp = 1;
		ansnum = 0;
		for(i = 1;i <= n;i ++)
		{
			for(j = 1;j <= c[i];j ++)
			{
				if(lcm[i][j] != tmp)
				{
					ansnum ++;
					ans[ansnum].x = i;
					ans[ansnum].y = j;
					int ttp = lcm[i][j];
					ans[ansnum].p = num[tmp].px;
					ans[ansnum].q = num[tmp].py;
					lcm[i][j] = tmp;
					lcm[num[tmp].px][num[tmp].py] = ttp;
					num[ttp].px = num[tmp].px;
					num[ttp].py = num[tmp].py;

				}
				tmp ++;
			}
		}
		printf("%d\n",ansnum);
		for(i = 1;i <= ansnum;i ++)
			printf("%d %d %d %d\n",ans[i].x,ans[i].y,ans[i].p,ans[i].q);
	}
	return 0;
}


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

#define N 55

int lcm[N][N],c[N];
struct node
{
	int x,y,p,q;
}ans[N * N * N];
struct nd
{
	int px,py;
}num[N * N * N];

int main()
{
	int i,j,ansnum,n;
	while(scanf("%d",&n) != EOF)
	{
		memset(lcm,0,sizeof(lcm));
		for(i = 1;i <= n;i ++)
			scanf("%d",&c[i]);
		for(i = 1;i <= n;i ++)
			for(j = 1;j <= c[i];j ++)
			{
				scanf("%d",&lcm[i][j]);
				num[lcm[i][j]].px = i;
				num[lcm[i][j]].py = j;
			}
		int tmp = 1;
		ansnum = 0;
		for(i = 1;i <= n;i ++)
		{
			for(j = 1;j <= c[i];j ++)
			{
				if(lcm[i][j] != tmp)
				{
					ansnum ++;
					ans[ansnum].x = i;
					ans[ansnum].y = j;
					int ttp = lcm[i][j];
					ans[ansnum].p = num[tmp].px;
					ans[ansnum].q = num[tmp].py;
					lcm[i][j] = tmp;
					lcm[num[tmp].px][num[tmp].py] = ttp;
					num[ttp].px = num[tmp].px;
					num[ttp].py = num[tmp].py;

				}
				tmp ++;
			}
		}
		printf("%d\n",ansnum);
		for(i = 1;i <= ansnum;i ++)
			printf("%d %d %d %d\n",ans[i].x,ans[i].y,ans[i].p,ans[i].q);
	}
	return 0;
}


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

#define N 55

int lcm[N][N],c[N];
struct node
{
	int x,y,p,q;
}ans[N * N * N];
struct nd
{
	int px,py;
}num[N];

int main()
{
	int i,j,ansnum,n;
	while(scanf("%d",&n) != EOF)
	{
		memset(lcm,0,sizeof(lcm));
		for(i = 1;i <= n;i ++)
			scanf("%d",&c[i]);
		for(i = 1;i <= n;i ++)
			for(j = 1;j <= c[i];j ++)
			{
				scanf("%d",&lcm[i][j]);
				num[lcm[i][j]].px = i;
				num[lcm[i][j]].py = j;
			}
		int tmp = 1;
		ansnum = 0;
		for(i = 1;i <= n;i ++)
		{
			for(j = 1;j <= c[i];j ++)
			{
				if(lcm[i][j] != tmp)
				{
					ansnum ++;
					ans[ansnum].x = i;
					ans[ansnum].y = j;
					int ttp = lcm[i][j];
					ans[ansnum].p = num[tmp].px;
					ans[ansnum].q = num[tmp].py;
					lcm[i][j] = tmp;
					lcm[num[tmp].px][num[tmp].py] = ttp;
					num[ttp].px = num[tmp].px;
					num[ttp].py = num[tmp].py;

				}
				tmp ++;
			}
		}
		printf("%d\n",ansnum);
		for(i = 1;i <= ansnum;i ++)
			printf("%d %d %d %d\n",ans[i].x,ans[i].y,ans[i].p,ans[i].q);
	}
	return 0;
}


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

#define N 55

int lcm[N][N],c[N];
struct node
{
	int x,y,p,q;
}ans[N * N];
struct nd
{
	int px,py;
}num[N];

int main()
{
	int i,j,ansnum,n;
	while(scanf("%d",&n) != EOF)
	{
		memset(lcm,0,sizeof(lcm));
		for(i = 1;i <= n;i ++)
			scanf("%d",&c[i]);
		for(i = 1;i <= n;i ++)
			for(j = 1;j <= c[i];j ++)
			{
				scanf("%d",&lcm[i][j]);
				num[lcm[i][j]].px = i;
				num[lcm[i][j]].py = j;
			}
		int tmp = 1;
		ansnum = 0;
		for(i = 1;i <= n;i ++)
			for(j = 1;j <= c[i];j ++)
			{
				if(lcm[i][j] != tmp)
				{
					ansnum ++;
					ans[ansnum].x = i;
					ans[ansnum].y = j;
					int ttp = lcm[i][j];
					ans[ansnum].p = num[tmp].px;
					ans[ansnum].q = num[tmp].py;
					lcm[i][j] = tmp;
					lcm[num[tmp].px][num[tmp].py] = ttp;

				}
				tmp ++;
			}
		printf("%d\n",ansnum);
		for(i = 1;i <= ansnum;i ++)
			printf("%d %d %d %d\n",ans[i].x,ans[i].y,ans[i].p,ans[i].q);
	}
	return 0;
}


#if 1
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<string>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

#define mp make_pair
#define pb push_back
#define x first
#define y second

//hello TL
int main()
{
//  freopen("output.txt","w",stdout);
    int n;
    int m[51]={};
    int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&m[i]);
        sum+=m[i];
    }
    int et[51][51]={};
    int mas[51][51]={};
    int l=0;
    int row=0;
    for(int i=0;i<sum;i++)
    {
        et[row][l++]=i+1;
        if(l==m[row])
        {
            row++;
            l=0;
        }
    }
    printf("%d\n",sum);
    int count_pr=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&mas[i][j]);
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            for(int k=0;k<n;k++)
                for(int r=0;r<m[k];r++)
                {
                    if(et[i][j]==mas[k][r])
                    {
                        mas[k][r]=mas[i][j];
                        mas[i][j]=et[i][j];
                        printf("%d %d %d %d\n",i+1,j+1,k+1,r+1);
                    }
                }
        }
    }
    return 0;
}
#endif
/*
1
4
4 3 2 1

3
3 2 1
4 3 5
6 1
2

*/


#if 1
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<string>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

#define mp make_pair
#define pb push_back
#define x first
#define y second
    char ans[25001][100]={};
//hello TL
int main()
{
//  freopen("output.txt","w",stdout);
    int n;
    int m[51]={};
    int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&m[i]);
        sum+=m[i];
    }
    int et[51][51]={};
    int mas[51][51]={};
    int l=0;
    int row=0;
    for(int i=0;i<sum;i++)
    {
        et[row][l++]=i+1;
        if(l==m[row])
        {
            row++;
            l=0;
        }
    }
    //printf("%d\n",sum-1);
    int count_pr=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&mas[i][j]);
        }
    }

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            for(int k=0;k<n;k++)
                for(int r=0;r<m[k];r++)
                {
                    if(et[i][j]==mas[k][r])
                    {
                        mas[k][r]=mas[i][j];
                        mas[i][j]=et[i][j];
                        if(!(i==k&&j==r))
                        sprintf(ans[count_pr++],"%d %d %d %d",i+1,j+1,k+1,r+1);
                    }
                }
        }
    }
    printf("%d\n",count_pr);
    for(int i=0;i<count_pr;i++)
        printf("%s\n",ans[i]);
    return 0;
}
#endif
/*
1
4
4 3 2 1

3
3 2 1
4 3 5
6 1
2

*/


#if 1
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<string>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

#define mp make_pair
#define pb push_back
#define x first
#define y second

int main()
{
//  freopen("output.txt","w",stdout);
    int n;
    int m[51]={};
    int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&m[i]);
        sum+=m[i];
    }
    int et[51][51]={};
    int mas[51][51]={};
    int l=0;
    int row=0;
    for(int i=0;i<sum;i++)
    {
        et[row][l++]=i+1;
        if(l==m[row])
        {
            row++;
            l=0;
        }
    }
    printf("%d\n",sum/2);
    int count_pr=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            int cache;
            scanf("%d",&cache);
            if(count_pr<sum/2)
            {
                for(int k=0;k<n;k++)
                    for(int r=0;r<m[k];r++)
                        if(et[k][r]==cache)
                        {
                            printf("%d %d %d %d\n",i+1,j+1,k+1,r+1);
                            count_pr++;
                        }
            }
        }
    }
    return 0;
}
#endif
/*
1
4
4 3 2 1

*/


#if 1
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<string>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

#define mp make_pair
#define pb push_back
#define x first
#define y second

int main()
{
    //freopen("output.txt","w",stdout);
    int n;
    int m[51]={};
    int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&m[i]);
        sum+=m[i];
    }
    int et[51][51]={};
    int mas[51][51]={};
    int l=0;
    int row=0;
    for(int i=0;i<sum;i++)
    {
        et[row][l++]=i+1;
        if(l==m[row])
        {
            row++;
            l=0;
        }
    }
    printf("%d\n",sum);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            int cache;
            scanf("%d",&cache);
            for(int k=0;k<n;k++)
                for(int r=0;r<m[k];r++)
                    if(et[k][r]==cache)
                    {
                        printf("%d %d %d %d\n",i+1,j+1,k+1,r+1);
                    }
        }
    }
    return 0;
}
#endif
/**/


#if 1
#include<iostream>
#include<cstdlib>
#include<conio.h>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<string>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

#define mp make_pair
#define pb push_back
#define x first
#define y second

//hello TL
int main()
{
//  freopen("output.txt","w",stdout);
    int n;
    int m[51]={};
    int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&m[i]);
        sum+=m[i];
    }
    int et[51][51]={};
    int mas[51][51]={};
    int l=0;
    int row=0;
    for(int i=0;i<sum;i++)
    {
        et[row][l++]=i+1;
        if(l==m[row])
        {
            row++;
            l=0;
        }
    }
    sum/=2;
    printf("%d\n",sum);
    int count_pr=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m[i];j++)
        {
            scanf("%d",&mas[i][j]);
        }
    }
    for(int i=0;i<n&&count_pr<sum;i++)
    {
        for(int j=0;j<m[i]&&count_pr<sum;j++)
        {
            for(int k=0;k<n&&count_pr<sum;k++)
                for(int r=0;r<m[k]&&count_pr<sum;r++)
                {
                    if(et[i][j]==mas[k][r])
                    {
                        mas[k][r]=mas[i][j];
                        mas[i][j]=et[i][j];
                        printf("%d %d %d %d\n",i+1,j+1,k+1,r+1);
                        count_pr++;
                    }
                }
        }
    }
    return 0;
}
#endif
/*
1
4
4 3 2 1

3
3 2 1
4 3 5
6 1
2

*/


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define pb push_back
#define mp make_pair
#define inf 2000000000000000LL
#define For(i,s,n) for (int i=s;i<=n;i++)
#define FOR(i,s,n) for (int i=s;i<n;i++)
#define Ford(i,s,n) for (int i=s;i>=n;i--)
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)

typedef long long ll;
using namespace std;
int n,c[1000],s,x,cnt,G[100][100];
pair <int,int> g[3000];

int main(){
    //freopen("i.txt","r",stdin);freopen("o.txt","w",stdout);
    cin>>n;
    For(i,1,n) cin>>c[i];
    For(i,1,n) s+=c[i];
    For(i,1,n)
       For(j,1,c[i]){
                     cin>>x;
                     G[i][j]=x;
                     g[x]=mp(i,j);
                     }
    cnt=0;
    cout<<s<<endl;
    For(i,1,n)
       For(j,1,c[i]){
                     cnt++;
                     cout<<i<<" "<<j<<" "<<g[cnt].first<<" "<<g[cnt].second<<endl;
                     g[G[i][j]]=mp(g[cnt].first,g[cnt].second);
                     }
    //system ("pause");
    }


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define pb push_back
#define mp make_pair
#define inf 2000000000000000LL
#define For(i,s,n) for (int i=s;i<=n;i++)
#define FOR(i,s,n) for (int i=s;i<n;i++)
#define Ford(i,s,n) for (int i=s;i>=n;i--)
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)

typedef long long ll;
using namespace std;
int n,c[1000],s,X,cnt,G[100][100],x[3000],y[3000],z[3000],t[3000];
pair <int,int> g[3000];

int main(){
    //freopen("i.txt","r",stdin);freopen("o.txt","w",stdout);
    cin>>n;
    For(i,1,n) cin>>c[i];
    For(i,1,n)
       For(j,1,c[i]){
                     cin>>X;
                     G[i][j]=X;
                     g[X]=mp(i,j);
                     }
    cnt=0;
    s=0;
    For(i,1,n)
       For(j,1,c[i]){
                     cnt++;
                     if (!(i==g[cnt].first&&j==g[cnt].second)){
                                                               s++;
                                                               x[s]=i;y[s]=j;z[s]=g[cnt].first;t[s]=g[cnt].second;
                                                               g[G[i][j]]=mp(g[cnt].first,g[cnt].second);
															   g[cnt]=mp(i,j);
															   G[z[s]][t[s]]=G[i][j];
															   G[i][j]=cnt;
                                                               }
                     }
    cout<<s<<endl;
    For(i,1,s)
       cout<<x[i]<<" "<<y[i]<<" "<<z[i]<<" "<<t[i]<<endl;
    //system ("pause");
    }


// rc.cpp
//

#include <math.h>
#include <string.h>

#include <iterator>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <algorithm>
#include <numeric>

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned __int64 uint64;

#define PI 3.1415926535897932384626433832795
#define EPS 1E-8

uint c[50][50],
	 l[50],
	 ix[2500],
	 jx[2500],
	 v[2500][4];

int main(int argc, char* argv[])
{
	uint n;
	cin >> n;

	uint s = 0;
	for (uint i = 0; i < n; ++i)
		cin >> l[i], s += l[i];

	for (uint i = 0; i < n; ++i)
	{
		for (uint j = 0; j < l[i]; ++j)
		{
			cin >> c[i][j];

			--c[i][j];
			ix[c[i][j]] = i;
			jx[c[i][j]] = j;
		}
	}

	uint iv = 0,
		 jv = 0,
		 cs = l[0],
		 ss = 0;
	for (uint k = 0; k < s - 1; ++k, ++jv)
	{
		if (k == cs)
		{
			++iv;
			cs += l[iv];
			jv = 0;
		}

		if (ix[k] != iv || jx[k] != jv)
		{
			v[ss][0] = iv + 1;
			v[ss][1] = jv + 1;
			v[ss][2] = ix[k] + 1;
			v[ss][3] = jx[k] + 1;

			++ss;
			ix[c[iv][jv]] = ix[k];
			jx[c[iv][jv]] = jx[k];
		}
	}

	cout << ss << endl;

	for (uint k = 0; k < ss; ++k)
		cout << v[k][0] << " " << v[k][1] << " " << v[k][2] << " " << v[k][3] << endl;

	return 0;
}


// rc.cpp
//

#include <math.h>
#include <string.h>

#include <iterator>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stack>
#include <algorithm>
#include <numeric>

using namespace std;

typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned __int64 uint64;

#define PI 3.1415926535897932384626433832795
#define EPS 1E-8

uint c[50][50],
	 l[50],
	 ix[2500],
	 jx[2500],
	 v[2500][4];

int main(int argc, char* argv[])
{
	uint n;
	cin >> n;

	uint s = 0;
	for (uint i = 0; i < n; ++i)
		cin >> l[i], s += l[i];

	for (uint i = 0; i < n; ++i)
	{
		for (uint j = 0; j < l[i]; ++j)
		{
			cin >> c[i][j];

			--c[i][j];
			ix[c[i][j]] = i;
			jx[c[i][j]] = j;
		}
	}

	uint iv = 0,
		 jv = 0,
		 cs = l[0],
		 ss = 0;
	for (uint k = 0; k < s - 1; ++k, ++jv)
	{
		if (k == cs)
		{
			++iv;
			cs += l[iv];
			jv = 0;
		}

		if (ix[k] != iv || jx[k] != jv)
		{
			v[ss][0] = iv + 1;
			v[ss][1] = jv + 1;
			v[ss][2] = ix[k] + 1;
			v[ss][3] = jx[k] + 1;

			++ss;
			ix[c[iv][jv]] = ix[k];
			jx[c[iv][jv]] = jx[k];
			c[ix[k]][jx[k]] = c[iv][jv];
		}
	}

	cout << ss << endl;

	for (uint k = 0; k < ss; ++k)
		cout << v[k][0] << " " << v[k][1] << " " << v[k][2] << " " << v[k][3] << endl;

	return 0;
}


// In the Name Of God

#include <iostream>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <string>
#include <bitset>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define inf int(~0ull/2)
#define ll_inf (int)1 << 62
#define int long long
#define float long double
#define fillArr( n, a )  for ( int i=0; i<n; i++ ) cin >> a[i] ;
#define fillArr2( n, a, b ) for ( int i=0; i<n; i++ ) cin >> a[i] >> b[i];
#define for2(i, a1, a2) for ( int (i) = (a1); (i)<(a2); (i)++ )
#define mp( a, b ) make_pair ( a, b )
#define add( a, b ) a.push_back ( b )
#define sz(a) (int) a.size( )
#define print(a) cout << #a << endl
#define log(a) cerr << #a << " " << a << endl
using namespace std;

const int maxn = 60, mod = 1e9+7;
int n, m, k;
int c[maxn];
int a[maxn][maxn];
int x1[200], x2[200], x3[200], x4[200];

void main( ){
    cin >> n;
    fillArr ( n, c );
    for2 ( i, 0, n ){
        for2 ( j, 0, c[i] )
            cin >> a[i][j];
    }
    int x = 0, y =0, index = 0;
    while ( 1 ){
        if ( x == n )
            break;
        int minX =x, minY =y;
        for2 ( i, x, n ){
            for2 ( j, (i == x ? y+1 : 0 ), c[i] ){
                if ( a[minX][minY] > a[i][j] )
                    minX = i, minY = j;
            }
        }
        if ( minX - x || minY - y )
            x1[index] = minX, x2[index] = minY, x3[index] = x, x4[index++] = y;
        swap ( a[minX][minY], a[x][y] );
        y++;
        if ( y == c[x] ){
            x++;
            y = 0;
        }
    }
    cout << index << endl;
    for2 ( i, 0, index )
        cout << x1[i]+1 << " " << x2[i]+1 << " " << x3[i]+1 << " " << x4[i]+1 << endl;
}


// In the Name Of God

#include <iostream>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <string>
#include <bitset>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define inf int(~0ull/2)
#define ll_inf (int)1 << 62
#define int long long
#define float long double
#define fillArr( n, a )  for ( int i=0; i<n; i++ ) cin >> a[i] ;
#define fillArr2( n, a, b ) for ( int i=0; i<n; i++ ) cin >> a[i] >> b[i];
#define for2(i, a1, a2) for ( int (i) = (a1); (i)<(a2); (i)++ )
#define mp( a, b ) make_pair ( a, b )
#define add( a, b ) a.push_back ( b )
#define sz(a) (int) a.size( )
#define print(a) cout << #a << endl
#define log(a) cerr << #a << " " << a << endl
using namespace std;

const int maxn = 60, mod = 1e9+7;
int n, m, k;
int c[maxn];
int a[maxn][maxn];

void main( ){
    cin >> n;
    fillArr ( n, c );
    for2 ( i, 0, n ){
        for2 ( j, 0, c[i] )
            cin >> a[i][j];
    }
    int x = 0, y =0;
    while ( 1 ){
        //log ( x );
        //log ( y );
        if ( x == n )
            break;
        int minX =x, minY =y;
        for2 ( i, x, n ){
            for2 ( j, (i == x ? y+1 : 0 ), c[i] ){
                if ( a[minX][minY] > a[i][j] )
                    minX = i, minY = j;
            }
        }
        if ( minX - x && minY - y )
            cout << minX + 1 << " " << minY + 1 << " " << x + 1 << " " << y + 1 << endl;
        swap ( a[minX][minY], a[x][y] );
        y++;
        if ( y == c[x] ){
            x++;
            y = 0;
        }
    }
}


// In the Name Of God

#include <iostream>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <string>
#include <bitset>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define inf int(~0ull/2)
#define ll_inf (int)1 << 62
#define int long long
#define float long double
#define fillArr( n, a )  for ( int i=0; i<n; i++ ) cin >> a[i] ;
#define fillArr2( n, a, b ) for ( int i=0; i<n; i++ ) cin >> a[i] >> b[i];
#define for2(i, a1, a2) for ( int (i) = (a1); (i)<(a2); (i)++ )
#define mp( a, b ) make_pair ( a, b )
#define add( a, b ) a.push_back ( b )
#define sz(a) (int) a.size( )
#define print(a) cout << #a << endl
#define log(a) cerr << #a << " " << a << endl
using namespace std;

const int maxn = 60, mod = 1e9+7;
int n, m, k;
int c[maxn];
int a[maxn][maxn];
int x1[3000], x2[3000], x3[3000], x4[3000];

void main( ){
    cin >> n;
    fillArr ( n, c );
    for2 ( i, 0, n ){
        for2 ( j, 0, c[i] )
            cin >> a[i][j];
    }
    int x = 0, y =0, index = 0;
    while ( 1 ){
        if ( x == n )
            break;
        int minX =x, minY =y;
        for2 ( i, x, n ){
            for2 ( j, (i == x ? y+1 : 0 ), c[i] ){
                if ( a[minX][minY] > a[i][j] )
                    minX = i, minY = j;
            }
        }
        if ( minX - x || minY - y )
            x1[index] = minX, x2[index] = minY, x3[index] = x, x4[index++] = y;
        swap ( a[minX][minY], a[x][y] );
        y++;
        if ( y == c[x] ){
            x++;
            y = 0;
        }
    }
    cout << index << endl;
    for2 ( i, 0, index )
        cout << x1[i]+1 << " " << x2[i]+1 << " " << x3[i]+1 << " " << x4[i]+1 << endl;
}


// In the Name Of God

#include <iostream>
#include <sstream>
#include <cmath>
#include <iomanip>
#include <string>
#include <bitset>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define inf int(~0ull/2)
#define ll_inf (int)1 << 62
#define int long long
#define float long double
#define fillArr( n, a )  for ( int i=0; i<n; i++ ) cin >> a[i] ;
#define fillArr2( n, a, b ) for ( int i=0; i<n; i++ ) cin >> a[i] >> b[i];
#define for2(i, a1, a2) for ( int (i) = (a1); (i)<(a2); (i)++ )
#define mp( a, b ) make_pair ( a, b )
#define add( a, b ) a.push_back ( b )
#define sz(a) (int) a.size( )
#define print(a) cout << #a << endl
#define log(a) cerr << #a << " " << a << endl
using namespace std;

const int maxn = 60, mod = 1e9+7;
int n, m, k;
int c[maxn];
int a[maxn][maxn];
int x1[300], x2[300], x3[300], x4[300];

void main( ){
    cin >> n;
    fillArr ( n, c );
    for2 ( i, 0, n ){
        for2 ( j, 0, c[i] )
            cin >> a[i][j];
    }
    int x = 0, y =0, index = 0;
    while ( 1 ){
        if ( x == n )
            break;
        int minX =x, minY =y;
        for2 ( i, x, n ){
            for2 ( j, (i == x ? y+1 : 0 ), c[i] ){
                if ( a[minX][minY] > a[i][j] )
                    minX = i, minY = j;
            }
        }
        if ( minX - x || minY - y )
            x1[index] = minX, x2[index] = minY, x3[index] = x, x4[index++] = y;
        swap ( a[minX][minY], a[x][y] );
        y++;
        if ( y == c[x] ){
            x++;
            y = 0;
        }
    }
    cout << index << endl;
    for2 ( i, 0, index )
        cout << x1[i]+1 << " " << x2[i]+1 << " " << x3[i]+1 << " " << x4[i]+1 << endl;
}


#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;

#define max(a,b) (a)>=(b) ? (a) : (b)
#define abs(x) (x)>=0 ? (x) : -(x)

int i,j,k,l,m,n;

int c[60];
int a[60][60];

int mk[60][60];
int im,ij;

int sw[4000][4];
void fm(int r,int co)
{
	im = r;
	ij = co;

	for (int j = co; j<= c[r];++j)
		if (a[r][j] < a[im][ij])
				ij = j;
	for (int i = r+1;i<=n;++i)
		for (int j = 1; j<= c[i];++j)
		{
			if (a[i][j] < a[im][ij])
			{
				im = i;
				ij = j;
			}
		}
}

int main()
{
	scanf("%d",&n);
	for (i = 1; i<=n;++i)
		scanf("%d",&(c[i]));

	for (int row = 1;row<=n;++row)
		for (int col = 1;col <=c[row];++col)
			scanf("%d",&(a[row][col]));
	int sc = 0;
	for (int row = 1;row<=n;++row)
		for (int col = 1; col<=c[row];++col)
		{
			fm(row,col);
			//swap
			if (row != im || col != ij)
			{
				sw[sc][0] = row;
				sw[sc][1] = col;
				sw[sc][2] = im;
				sw[sc][3] = ij;
				a[row][col]^=a[im][ij]^=a[row][col]^=a[im][ij];
				sc++;
			}
		}

	printf("%d\n",sc);
	for (int i = 0 ;i<sc;++i)
		printf("%d %d %d %d\n",sw[i][0],sw[i][1],sw[i][2],sw[i][3]);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;

#define max(a,b) (a)>=(b) ? (a) : (b)
#define abs(x) (x)>=0 ? (x) : -(x)

int i,j,k,l,m,n;

int c[60];
int a[60][60];

int mk[60][60];
int im,ij;

int sw[4000][4];
void fm(int r,int co)
{
	im = r;
	ij = co;

	for (int j = co; j<= c[r];++j)
		if (a[r][j] < a[im][ij])
				ij = j;
	for (int i = r+1;i<=n;++i)
		for (int j = 1; j<= c[i];++j)
		{
			if (a[i][j] < a[im][ij])
			{
				im = i;
				ij = j;
			}
		}
}

int main()
{
	scanf("%d",&n);
	for (i = 1; i<=n;++i)
		scanf("%d",&(c[i]));

	for (int row = 1;row<=n;++row)
		for (int col = 1;col <=c[row];++col)
			scanf("%d",&(a[row][col]));
	int sc = 0;
	for (int row = 1;row<=n;++row)
		for (int col = 1; col<=c[row];++col)
		{
			fm(row,col);
			//swap
			sw[sc][0] = row;
			sw[sc][1] = col;
			sw[sc][2] = im;
			sw[sc][3] = ij;
			a[row][col]^=a[im][ij]^=a[row][col]^=a[im][ij];
			sc++;
		}

	printf("%d\n",sc);
	for (int i = 0 ;i<sc;++i)
		printf("%d %d %d %d\n",sw[i][0],sw[i][1],sw[i][2],sw[i][3]);

	return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
struct node{
    int x,y;
}Node[2600];
int arr[55][55];
int main()
{
    int x;
   int n,i,j;
   int num[60];
    while(scanf("%d",&n)!=EOF){
        for(i=1;i<=n;i++){
            scanf("%d",&num[i]);
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                scanf("%d",&x);
                arr[i][j]=x;
                 Node[x].x=i;
                Node[x].y=j;
            }
        }
        int cnt=0;
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                cnt++;
                if( !(Node[cnt].x==i && Node[cnt].y==j) ){
                    printf("%d %d %d %d\n",i,j,Node[cnt].x,Node[cnt].y);
                    x=arr[i][j];
                    Node[x].x=Node[cnt].x;
                    Node[x].y=Node[cnt].y;
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
struct node{
    int x,y;
}Node[2600];
struct aaaa{
    int a,b,x,y;
}XXX[2600];
int arr[55][55];
int main()
{
    int x;
   int n,i,j;
   int m;
   int num[60];
    while(scanf("%d",&n)!=EOF){
        for(i=1;i<=n;i++){
            scanf("%d",&num[i]);
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                scanf("%d",&x);
                arr[i][j]=x;
                Node[x].x=i;
                Node[x].y=j;
            }
        }
        m=0;
        int cnt=0;
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                cnt++;
                if( !(Node[cnt].x==i && Node[cnt].y==j) ){
                    XXX[m].a=i;
                    XXX[m].b=j;
                    XXX[m].x=Node[cnt].x;
                    XXX[m].y=Node[cnt].y;
                    m++;
         //           printf("%d %d %d %d\n",i,j,Node[cnt].x,Node[cnt].y);
                    x=arr[i][j];
                    Node[x].x=Node[cnt].x;
                    Node[x].y=Node[cnt].y;
                    arr[Node[x].x][Node[x].y]=x;
                }
            }
        }
        printf("%d\n",m);
        for(i=0;i<m;i++){
            printf("%d %d %d %d\n",XXX[i].a,XXX[i].b,XXX[i].x,XXX[i].y);
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
struct node{
    int x,y;
}Node[2600];
struct aaaa{
    int a,b,x,y;
}XXX[2600];
int arr[55][55];
int main()
{
    int x;
   int n,i,j;
   int m;
   int num[60];
    while(scanf("%d",&n)!=EOF){
        for(i=1;i<=n;i++){
            scanf("%d",&num[i]);
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                scanf("%d",&x);
                arr[i][j]=x;
                 Node[x].x=i;
                Node[x].y=j;
            }
        }
        m=0;
        int cnt=0;
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                cnt++;
                if( !(Node[cnt].x==i && Node[cnt].y==j) ){
                    XXX[m].a=i;
                    XXX[m].b=j;
                    XXX[m].x=Node[cnt].x;
                    XXX[m].y=Node[cnt].y;
                    m++;
         //           printf("%d %d %d %d\n",i,j,Node[cnt].x,Node[cnt].y);
                    x=arr[i][j];
                    Node[x].x=Node[cnt].x;
                    Node[x].y=Node[cnt].y;
                }
            }
        }
        printf("%d\n",m);
        for(i=0;i<m;i++){
            printf("%d %d %d %d\n",XXX[i].a,XXX[i].b,XXX[i].x,XXX[i].y);
        }
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
using namespace std;
struct node{
    int x,y;
}Node[2600];
struct aaaa{
    int a,b,x,y;
}XXX[2600];
int arr[55][55];
int main()
{
    int x;
   int n,i,j;
   int m;
   int num[60];
    while(scanf("%d",&n)!=EOF){
        for(i=1;i<=n;i++){
            scanf("%d",&num[i]);
        }
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                scanf("%d",&x);
                arr[i][j]=x;
                Node[x].x=i;
                Node[x].y=j;
            }
        }
        m=0;
        int cnt=0;
        for(i=1;i<=n;i++){
            for(j=1;j<=num[i];j++){
                cnt++;
                if( !(Node[cnt].x==i && Node[cnt].y==j) ){
                    XXX[m].a=i;
                    XXX[m].b=j;
                    XXX[m].x=Node[cnt].x;
                    XXX[m].y=Node[cnt].y;
                    m++;
         //           printf("%d %d %d %d\n",i,j,Node[cnt].x,Node[cnt].y);
                    x=arr[i][j];
                    Node[x].x=Node[cnt].x;
                    Node[x].y=Node[cnt].y;
                }
            }
        }
        printf("%d\n",m);
        for(i=0;i<m;i++){
            printf("%d %d %d %d\n",XXX[i].a,XXX[i].b,XXX[i].x,XXX[i].y);
        }
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <cmath>

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

typedef long long ll;

using namespace std;

int main()
{
    int n, c[100], a[100][100], i, j, k, s = 0, ki, kj, qa = 0, w[100][4];

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> c[i], s += c[i];

    for (i = 0; i < n; i++)
        for (j = 0; j < c[i]; j++)
            cin >> a[i][j];

    ki = kj = 0;
    for (k = 0; k < s; k++)
    {
        int li = ki, lj = kj;

        for (i = ki; i < n; i++)
            for (j = (i == ki ? kj : 0); j < c[i]; j++)
                if (a[i][j] < a[li][lj])
                    li = i, lj = j;

        if (li != ki || lj != kj)
            w[qa][0] = li + 1, w[qa][1] = lj + 1, w[qa][2] = ki + 1, w[qa][3] = kj + 1, qa++,
            swap(a[li][lj], a[ki][kj]);

        if (kj == c[ki] - 1)
            ki++, kj = 0;
        else
            kj++;
    }

    cout << qa << endl;
    for (i = 0; i < qa; i++)
        cout << w[i][0] << ' ' << w[i][1] << ' ' << w[i][2] << ' ' << w[i][3] << endl;

    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <cmath>

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

typedef long long ll;

using namespace std;

int main()
{
    int n, c[10000], a[1000][1000], i, j, k, s = 0, ki, kj, qa = 0, w[10000][4];

    cin >> n;

    for (i = 0; i < n; i++)
        cin >> c[i], s += c[i];

    for (i = 0; i < n; i++)
        for (j = 0; j < c[i]; j++)
            cin >> a[i][j];

    ki = kj = 0;
    for (k = 0; k < s; k++)
    {
        int li = ki, lj = kj;

        for (i = ki; i < n; i++)
            for (j = (i == ki ? kj : 0); j < c[i]; j++)
                if (a[i][j] < a[li][lj])
                    li = i, lj = j;

        if (li != ki || lj != kj)
            w[qa][0] = li + 1, w[qa][1] = lj + 1, w[qa][2] = ki + 1, w[qa][3] = kj + 1, qa++,
            swap(a[li][lj], a[ki][kj]);

        if (kj == c[ki] - 1)
            ki++, kj = 0;
        else
            kj++;
    }

    cout << qa << endl;
    for (i = 0; i < qa; i++)
        cout << w[i][0] << ' ' << w[i][1] << ' ' << w[i][2] << ' ' << w[i][3] << endl;

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAXN = 50 + 10;
int num[MAXN];
int map[MAXN][MAXN];

struct P
{
	int r, c;
	int num;
}p[MAXN*MAXN];

struct P2
{
	int r1, c1;
	int r2, c2;
}ans[MAXN*MAXN];

int main()
{
	int n, i, j, k, p, cut, res;
	while(scanf("%d", &n) != EOF)
	{
		for( i=1; i<=n; i++ ) scanf("%d", &num[i]);
		for( i=1; i<=n; i++ )
		{
			for( j=1; j<=num[i]; j++ )
			{
				scanf("%d", &map[i][j]);
			}
		}
		cut = 0;
		res = 0;
		for( i=1; i<=n; i++ )
		{
			for( j=1; j<=num[i]; j++ )
			{
				cut++;
				if(map[i][j] != cut)
				{
					bool flag = false;
					for( k=1; k<=n; k++ )
					{
						for( p=1; p<=num[k]; p++ )
						{
							if(map[k][p] == cut)
							{
								map[k][p] = map[i][j];
								map[i][j] = cut;
								flag = true;
								break;
							}
						}
						if(flag) break;
					}
					ans[res].r1 = i, ans[res].c1 = j, ans[res].r2 = k, ans[res].c2 = p;
					res++;
				}
			}

		}
		printf("%d\n", res);
		for( i=0; i<res; i++ )
		{
			printf("%d %d %d %d\n", ans[i].r1, ans[i].c1, ans[i].r2, ans[i].c2);
		}
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAXN = 50 + 10;
int num[MAXN];
int map[MAXN][MAXN];

struct P
{
	int r, c;
	int num;
}p[MAXN*MAXN];

struct P2
{
	int r1, c1;
	int r2, c2;
}ans[MAXN*MAXN];
bool flag[MAXN][MAXN];

bool cmp(const P & a, const P & b)
{
	return a.num < b.num;
}
int cut, res;
void Solve(int x, int y)
{
	int i;
	for( i=0; i<cut; i++ )
	{
		if(flag[p[i].r][p[i].c]) continue;
		int temp = map[p[i].r][p[i].c];
		ans[res].r1 = x, ans[res].c1 = y, ans[res].r2 = p[i].r, ans[res].c2 = p[i].c;
		res++;
		map[p[i].r][p[i].c] = map[x][y];
		map[x][y] = temp;
		flag[p[i].r][p[i].c] = flag[x][y] = 1;
		break;
	}
}

int main()
{
	int n, i, j;
	while(scanf("%d", &n) != EOF)
	{
		memset(flag, 0, sizeof(flag));
		cut = 0;
		for( i=1; i<=n; i++ ) scanf("%d", &num[i]);
		for( i=1; i<=n; i++ )
		{
			for( j=1; j<=num[i]; j++ )
			{
				scanf("%d", &map[i][j]);
				p[cut].num = map[i][j];
				p[cut].r = i;
				p[cut].c = j;
				cut++;
			}
		}
		sort(p, p + cut, cmp);
		res = 0;
		for( i=1; i<=n; i++ )
		{
			for( j=1; j<=num[i]; j++ )
			{
				if(i-1>=1)
				{
					if(map[i][j] < map[i-1][j]) Solve(i-1, j);
				}
				if(j-1>=1)
				{
					if(map[i][j] < map[i][j-1]) Solve(i, j-1);
				}
				flag[i][j] = 1;
			}

		}
		printf("%d\n", res);
		for( i=0; i<res; i++ )
		{
			printf("%d %d %d %d\n", ans[i].r1, ans[i].c1, ans[i].r2, ans[i].c2);
		}
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
struct key
{
	int i,j,val,i2,j2;
};
int oper[10000][4];
key mass[10000];
void main()
{
	int n;
	scanf("%d",&n);
	int c[50];
	for (int i=0;i<n;i++)
	{
		scanf("%d",&c[i]);
	}
	int p=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<c[i];j++)
		{
			int a;
			scanf("%d",&a);
			mass[p].val=a;
			mass[p].i=i;
			mass[p].j=j;

			p++;
		}
	}
	for (int i=0;i<p;i++)
	{
		for (int j=i+1;j<p;j++)
		{
			if (mass[i].val>mass[j].val)
			{
				key t=mass[i];
				mass[i]=mass[j];
				mass[j]=t;
			}
		}
	}
	int op=0;
	int p2=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<c[i];j++)
		{
			mass[p2].i2=i;
			mass[p2].j2=j;
			if (mass[p2].i!=mass[p2].i2||mass[p2].j!=mass[p2].j2)
			{
				oper[op][0]=mass[p2].i;
				oper[op][1]=mass[p2].j;
				oper[op][2]=mass[p2].i2;
				oper[op][3]=mass[p2].j2;
				for (int k=0;k<p;k++)
					if (mass[k].i==i&&mass[k].j==j)
					{
						mass[k].i=mass[p2].i;
						mass[k].j=mass[p2].j;
						mass[p2].i=i;
						mass[p2].j=i;
						break;

					}

				op++;
			}
			p2++;
		}
	}
	printf("%d\n",op);
	for (int i=0;i<op;i++)
		printf("%d %d %d %d\n",oper[i][0]+1,oper[i][1]+1,oper[i][2]+1,oper[i][3]+1);

}


#include <stdio.h>
#include <stdlib.h>
struct key
{
	int i,j,val,i2,j2;
};
int oper[10000][4];
key mass[10000];
void main()
{
	int n;
	scanf("%d",&n);
	int c[50];
	for (int i=0;i<n;i++)
	{
		scanf("%d",&c[i]);
	}
	int p=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<c[i];j++)
		{
			int a;
			scanf("%d",&a);
			mass[p].val=a;
			mass[p].i=i;
			mass[p].j=j;

			p++;
		}
	}
	for (int i=0;i<p;i++)
	{
		for (int j=i+1;j<p;j++)
		{
			if (mass[i].val>mass[j].val)
			{
				key t=mass[i];
				mass[i]=mass[j];
				mass[j]=t;
			}
		}
	}
	int op=0;
	int p2=0;
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<c[i];j++)
		{
			mass[p2].i2=i;
			mass[p2].j2=j;
			if (mass[p2].i!=mass[p2].i2||mass[p2].j!=mass[p2].j2)
			{
				oper[op][0]=mass[p2].i;
				oper[op][1]=mass[p2].j;
				oper[op][2]=mass[p2].i2;
				oper[op][3]=mass[p2].j2;
				for (int k=0;k<p;k++)
					if (mass[k].i==i&&mass[k].j==j)
					{
						mass[k].i=mass[p2].i;
						mass[k].j=mass[p2].j;
						mass[p2].i=i;
						mass[p2].j=j;
						break;

					}

				op++;
			}
			p2++;
		}
	}
	printf("%d\n",op);
	for (int i=0;i<op;i++)
		printf("%d %d %d %d\n",oper[i][0]+1,oper[i][1]+1,oper[i][2]+1,oper[i][3]+1);

}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    //freopen("1.txt","r",stdin);
    int n,s=0;
    cin>>n;
    vector <int > c(n);
    vector <vector <int > > v(n);
    for(int i=0;i<n;i++)
        scanf("%d",&c[i]);
    for(int i=0;i<n;i++)
        s+=c[i];
    vector <pair <int ,int > > d(s),beg,end;
    for(int i=0;i<n;i++)
        for(int j=0;j<c[i];j++)
        {
            int a;
            scanf("%d",&a);
            a--;
            d[a]=make_pair(i,j);
            v[i].push_back(a);
        }
    int p=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<c[i];j++)
        {
            if(v[i][j]!=p)
            {
                beg.push_back(make_pair(i,j));
                end.push_back(d[p]);
                d[v[i][j]]=d[p];
                v[d[p].first][d[p].second]=v[i][j];
            }
            p++;
        }
    cout<<beg.size()<<endl;
    for(int i=0;i<beg.size();i++)
        cout<<beg[i].first+1<<' '<<beg[i].second+1<<' '<<end[i].first+1<<' '<<end[i].second+1<<endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    //freopen("1.txt","r",stdin);
    int n,s=0;
    cin>>n;
    vector <int > c(n);
    vector <vector <int > > v(n);
    for(int i=0;i<n;i++)
        scanf("%d",&c[i]);
    for(int i=0;i<n;i++)
        s+=c[i];
    vector <pair <int ,int > > d(s),beg,end;
    for(int i=0;i<n;i++)
        for(int j=0;j<c[i];j++)
        {
            int a;
            scanf("%d",&a);
            a--;
            d[a]=make_pair(i,j);
            v[i].push_back(a);
        }
    int p=0;
    for(int i=0;i<n;i++)
        for(int j=0;j<c[i];j++)
        {
            if(v[i][j]!=p)
            {
                beg.push_back(make_pair(i,j));
                end.push_back(d[p]);
                d[v[i][j]]=d[p];
            }
            p++;
        }
    cout<<beg.size()<<endl;
    for(int i=0;i<beg.size();i++)
        cout<<beg[i].first+1<<' '<<beg[i].second+1<<' '<<end[i].first+1<<' '<<end[i].second+1<<endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
using namespace std;
#define mems(arr, val) memset(arr, val, sizeof(arr))
#define forn(from, to) for(int i = from; i < to; ++i)
typedef long long LL;

int main()
{
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	vector<vector<int>> A(n);
	vector<int> c(n);
	int s = 0;
	for (int i = 0; i < n; ++i)
	{

		cin>>c[i];
		s += c[i];
		A[i].resize(c[i]);
	}

	int counter = 0;
	vector<pair<int, int>> S(s);

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < c[i]; ++j)
		{
			cin>>A[i][j];
			A[i][j]--;
			S[A[i][j]] = make_pair(i, j);
		}
	}

	vector<pair<pair<int, int>, pair<int, int>>> ans;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < c[i]; ++j)
		{
			if (A[i][j] == counter)
			{

			}
			else
			{
				ans.push_back(make_pair(make_pair(i, j), S[counter]));
				A[S[counter].first][S[counter].second] = A[i][j];
				swap(S[counter], S[A[i][j]]);

			}
			counter++;
		}
	}
	cout<<ans.size()<<endl;
	for(int i = 0; i < ans.size(); ++i)
	{
		cout<<ans[i].first.first + 1<<" "<<ans[i].first.second + 1<<" "<<ans[i].second.first + 1<<" "<<ans[i].second.second + 1<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
using namespace std;
#define mems(arr, val) memset(arr, val, sizeof(arr))
#define forn(from, to) for(int i = from; i < to; ++i)
typedef long long LL;

int main()
{
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	vector<vector<int>> A(n, vector<int> (n));
	vector<int> c(n);
	int s = 0;
	for (int i = 0; i < n; ++i)
	{
		cin>>c[i];
		s += c[i];
	}

	int counter = 0;
	vector<pair<int, int>> S(s);

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < c[i]; ++j)
		{
			cin>>A[i][j];
			A[i][j]--;
			S[A[i][j]] = make_pair(i, j);
		}
	}

	vector<pair<pair<int, int>, pair<int, int>>> ans;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < c[i]; ++j)
		{
			if (A[i][j] == counter)
			{

			}
			else
			{
				ans.push_back(make_pair(make_pair(i, j), S[counter]));
				swap(S[counter], S[A[i][j]]);
				A[S[counter].first][S[counter].second] = A[i][j];
			}
			counter++;
		}
	}
	cout<<ans.size()<<endl;
	for(int i = 0; i < ans.size(); ++i)
	{
		cout<<ans[i].first.first + 1<<" "<<ans[i].first.second + 1<<" "<<ans[i].second.first + 1<<" "<<ans[i].second.second + 1<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <vector>
#include <sstream>
#include <algorithm>
#include <cmath>
using namespace std;
#define mems(arr, val) memset(arr, val, sizeof(arr))
#define forn(from, to) for(int i = from; i < to; ++i)
typedef long long LL;

int main()
{
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	vector<vector<int>> A(n);
	vector<int> c(n);
	int s = 0;
	for (int i = 0; i < n; ++i)
	{

		cin>>c[i];
		s += c[i];
		A[i].resize(c[i]);
	}

	int counter = 0;
	vector<pair<int, int>> S(s);

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < c[i]; ++j)
		{
			cin>>A[i][j];
			A[i][j]--;
			S[A[i][j]] = make_pair(i, j);
		}
	}

	vector<pair<pair<int, int>, pair<int, int>>> ans;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < c[i]; ++j)
		{
			if (A[i][j] == counter)
			{

			}
			else
			{
				ans.push_back(make_pair(make_pair(i, j), S[counter]));
				swap(S[counter], S[A[i][j]]);
				A[S[counter].first][S[counter].second] = A[i][j];
			}
			counter++;
		}
	}
	cout<<ans.size()<<endl;
	for(int i = 0; i < ans.size(); ++i)
	{
		cout<<ans[i].first.first + 1<<" "<<ans[i].first.second + 1<<" "<<ans[i].second.first + 1<<" "<<ans[i].second.second + 1<<endl;
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS

#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <bitset>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;

#define ALL(v) v.begin(), v.end()
#define SZ(v) (int) v.size()
#define SQR(x) ((x) * (x))
#define MP make_pair

const int MAXN = 55;

int c[MAXN];

int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &c[i]);
	}
	vector<pair<int, pii> > v;
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < c[i]; ++j) {
			int val;
			scanf("%d", &val);
			v.push_back(MP(val, MP(i + 1, j + 1)));
		}
	vector<pair<pii, pii> > res;
	for (int i = 0; i + 1 < SZ(v); ++i)
		for (int j = i + 1; j < SZ(v); ++j)
			if (v[i].first > v[j].first) {
				res.push_back(MP(v[i].second, v[j].second));
				swap(v[i], v[j]);
			}
	printf("%d\n", SZ(res));
	for (int i = 0; i < SZ(res); ++i) {
		printf("%d %d %d %d\n", res[i].first.first, res[i].first.second, res[i].second.first, res[i].second.second);
	}
	return 0;
}


#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS

#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <bitset>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;

#define ALL(v) v.begin(), v.end()
#define SZ(v) (int) v.size()
#define SQR(x) ((x) * (x))
#define MP make_pair

const int MAXN = 55;

struct dt {
	int i, j, val;

	dt(int i, int j, int val) : i(i), j(j), val(val) {}
};

int c[MAXN];

int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", &c[i]);
	}
	vector<dt> v;
	int id = 0;
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < c[i]; ++j) {
			int val;
			scanf("%d", &val);
			v.push_back(dt(i, j, val));
		}
	vector<pair<pii, pii> > res;
	for (int i = 0; i < SZ(v); ++i)
		if (v[i].val != i + 1)
			for (int j = i + 1; j < SZ(v); ++j)
				if (v[j].val == i + 1) {
					res.push_back(MP(MP(v[i].i, v[i].j), MP(v[j].i, v[j].j)));
					v[j].val = v[i].val;
				}
	printf("%d\n", SZ(res));
	for (int i = 0; i < SZ(res); ++i) {
		printf("%d %d %d %d\n", res[i].first.first + 1, res[i].first.second + 1, res[i].second.first + 1, res[i].second.second + 1);
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

static int a[50][50];
int *c;
int n;

struct A
{
	int ai;
	int aj;
	int newai;
	int newaj;
};

void find_min(int Ifrom, int Jfrom, int &IResult, int &JResult, int Sought)
{
	for (int i = Ifrom; i < n; i++)
	{
		int j;
		for (j = Jfrom; j < c[i]; j++)
		{
			JResult = j;
			if (a[i][j] == Sought) break;
		}
		IResult = i;
		if (a[i][j] == Sought) break;
		Jfrom = 0;
	}
}

int main()
{
	cin >> n;
	c = new int [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];
		}
	}
	int Sought = 1;
	int new_i, new_j;
	int m = 0;
	vector<A> r;
	A temp;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < c[i]; j++)
		{
			find_min(i, j, new_i, new_j, Sought);
			if (i != new_i || j != new_j)
			{
				m++;
				temp.ai = i;
				temp.aj = j;
				temp.newai = new_i;
				temp.newaj = new_j;
				r.push_back(temp);
				swap(a[i][j], a[new_i][new_j]);
			}
			Sought++;
		}
	}
	cout << m << endl;
	for (int i = 0; i < r.size(); i++)
	{
		cout << r[i].ai + 1 << ' ' << r[i].aj + 1 << ' ' << r[i].newai + 1 << ' ' << r[i].newaj + 1 << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

static int a[50][50];
int *c;
int n;

struct A
{
	int ai;
	int aj;
	int newai;
	int newaj;
};

void find_min(int &IResult, int &JResult, int Sought)
{
	for (int i = 0; i < n; i++)
	{
		int j;
		for (j = 0; j < c[i]; j++)
		{
			JResult = j;
			if (a[i][j] == Sought) break;
		}
		IResult = i;
		if (a[i][j] == Sought) break;
	}
}

int main()
{
	cin >> n;
	c = new int [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];
		}
	}
	int Sought = 1;
	int new_i, new_j;
	int m = 0;
	vector<A> r;
	A temp;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < c[i]; j++)
		{
			find_min(new_i, new_j, Sought);
			if (i != new_i || j != new_j)
			{
				m++;
				temp.ai = i;
				temp.aj = j;
				temp.newai = new_i;
				temp.newaj = new_j;
				r.push_back(temp);
				swap(a[i][j], a[new_i][new_j]);
			}
			Sought++;
		}
	}
	cout << m << endl;
	for (int i = 0; i < r.size(); i++)
	{
		cout << r[i].ai + 1 << ' ' << r[i].aj + 1 << ' ' << r[i].newai + 1 << ' ' << r[i].newaj + 1 << endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

static int a[50][50];
int *c;
int n;

struct A
{
    int ai;
    int aj;
    int newai;
    int newaj;
};

void find_min(int Ifrom, int Jfrom, int &IResult, int &JResult, int Sought)
{
    for (int i = Ifrom; i < n; i++)
    {
        int j;
        for (j = Jfrom; j < c[i]; j++)
        {
            JResult = j;
            if (a[i][j] == Sought) break;
        }
        IResult = i;
        if (a[i][j] == Sought) break;
        Jfrom = 0;
    }
}

int main()
{
    cin >> n;
    c = new int [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];
        }
    }
    int Sought = 1;
    int new_i, new_j;
    int m = 0;
    vector<A> r;
    A temp;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < c[i]; j++)
        {
            find_min(i, j, new_i, new_j, Sought);
            if (i != new_i || j != new_j)
            {
                m++;
                temp.ai = i;
                temp.aj = j;
                temp.newai = new_i;
                temp.newaj = new_j;
                r.push_back(temp);
                swap(a[i][j], a[new_i][new_j]);
            }
            Sought++;
        }
    }
    cout << n << endl;
    for (int i = 0; i < r.size(); i++)
    {
        cout << r[i].ai + 1 << ' ' << r[i].aj + 1 << ' ' << r[i].newai + 1 << ' ' << r[i].newaj + 1 << endl;
    }
    return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <exception>
#include <numeric>

using namespace std;

typedef vector< vector<long long> > vvl;
typedef vector< long long> vl;
typedef pair<long, long > ll;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef pair<long, pair<long, long>> lll;
typedef vector<lll> vlll;
typedef vector<vvl> vvvl;
typedef vector<set<long>> vs;
typedef long long lo;

lo table[100][100], c[100];
vvl ans;
pair<lo, lo> find(lo k){
	for (lo i=0;i<100;i++)
		for (lo j=0;j<100;j++)
			if (table[i][j]==k) return make_pair(i, j);
}
pair<lo, lo> nextPos(pair<lo, lo> pos){
	if (pos.second +1 < c[pos.first]) pos.second++;
	else {
		pos.first ++;
		pos.second=0;
	}
	return pos;
}
void recordSwap(pair<lo, lo> from, pair<lo, lo> to){
	vl row;
	row.push_back(from.first+1);
	row.push_back(from.second+1);
	row.push_back(to.first+1);
	row.push_back(to.second+1);
	ans.push_back(row);
	swap(table[from.first][from.second], table[to.first][to.second]);
}
int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	for (lo i=0;i<100;i++)
		for (lo j=0;j<100;j++)
			table[i][j]=-1;
	lo n, s=0;
	scanf("%I64d", &n);
	for (lo i=0;i<n;i++){
		scanf("%I64d", &c[i]);
		s+=c[i];
	}
	for (lo i=0;i<n;i++)
		for (lo j=0;j<c[i];j++)
			scanf("%I64d", &table[i][j]);
	pair<lo,lo> from=make_pair(0,0);
	for (lo k=1;k<=s;k++){
		pair<lo, lo> to=find(k);
		if (from!=to) recordSwap(from, to);
		from=nextPos(from);
	}
	printf("%ld\n", ans.size());
	for (vvl::iterator it=ans.begin();it!=ans.end();it++)
		printf("%I64d %I64d %I64d %I64d\n", (*it)[0], (*it)[1], (*it)[2], (*it)[3]);
	return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <exception>
#include <numeric>

using namespace std;

typedef vector< vector<long long> > vvl;
typedef vector< long long> vl;
typedef pair<long, long > ll;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef pair<long, pair<long, long>> lll;
typedef vector<lll> vlll;
typedef vector<vvl> vvvl;
typedef vector<set<long>> vs;
typedef long long lo;

lo table[100][100], c[100];
vvl ans;
pair<lo, lo> find(lo k){
	for (lo i=0;i<100;i++)
		for (lo j=0;j<100;j++)
			if (table[i][j]==k) return make_pair(i, j);
}
pair<lo, lo> nextPos(pair<lo, lo> pos){
	if (pos.second +1 < c[pos.first]) pos.second++;
	else pos.first ++;
	return pos;
}
void recordSwap(pair<lo, lo> from, pair<lo, lo> to){
	vl row;
	row.push_back(from.first+1);
	row.push_back(from.second+1);
	row.push_back(to.first+1);
	row.push_back(to.second+1);
	ans.push_back(row);
	swap(table[from.first][from.second], table[to.first][to.second]);
}
int main() {
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	for (lo i=0;i<100;i++)
		for (lo j=0;j<100;j++)
			table[i][j]=-1;
	lo n, s=0;
	scanf("%I64d", &n);
	for (lo i=0;i<n;i++){
		scanf("%I64d", &c[i]);
		s+=c[i];
	}
	for (lo i=0;i<n;i++)
		for (lo j=0;j<c[i];j++)
			scanf("%I64d", &table[i][j]);
	pair<lo,lo> from=make_pair(0,0);
	for (lo k=1;k<=s;k++){
		pair<lo, lo> to=find(k);
		if (from!=to) recordSwap(from, to);
		from=nextPos(from);
	}
	printf("%ld\n", ans.size());
	for (vvl::iterator it=ans.begin();it!=ans.end();it++)
		printf("%I64d %I64d %I64d %I64d\n", (*it)[0], (*it)[1], (*it)[2], (*it)[3]);
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){int ans=0;vector<int>vec;
int n; cin>>n;
int c[50];
for(int i=0;i<n;i++)
{
	cin>>c[i];
	//s++;
}
int arr[50][50];int arr1[50][50];
for(int i=0;i<n;i++)
{
for(int k=0;k<c[i];k++)
{
cin>>arr[i][k];
}
}int l=1;
for(int i=0;i<n;i++)
{
for(int k=0;k<c[i];k++)
{
arr1[i][k]=l;l++;
}
}
//////////
/*for(int i=0;i<n;i++)
{
sort(arr[i],arr[i]+c[i]);
}*/
for(int i=0;i<n;i++)
{
for(int k=0;k<c[i];k++)
{
	if(arr[i][k]!=arr1[i][k])
	{vec.push_back(i+1);
	vec.push_back(k+1);
	for(int j=0;j<n;j++)
{
for(int q=0;q<c[i];q++)
{
if(arr[j][q]==arr1[i][k])
{vec.push_back(j+1);
vec.push_back(q+1);
arr[j][q]=arr[i][k];}
}
	}
	arr[i][k]=arr1[i][k];
		ans++;
	}
}
}
cout<<ans<<endl;
for(int i=0;i<vec.size();i++)
{
	cout<<vec[i]<<" ";
	if((i+1)%4==0)
cout<<endl;
}

}


#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=0;i<v.size();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].c<<" ";
		cout<<store[i].d<<"\n";
	}

}


#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].c<<" ";
		cout<<store[i].d<<"\n";
	}

}