char dui[1000];
int i = -1, p = 0, flag[100];
void rankgame(int s)
{
	if(i + 1 == p && p != 0)return;
	cin.get(dui[s]);
	i ++;
	if(dui[s] != dui[0])
	{
		cout << flag[s - 1] << ' ' << i << endl;
		p = p + 2;
		rankgame(s - 1);
	}
	else
	{
		flag[s] = i;
		s ++;
		rankgame(s);
	}
}

int main()
{
	rankgame(0);
	return 0;
}


int main()
{
	char line[100], boy, girl;
	int i, j, l, k=0, m, n=0, numb[100]={0}, numg[100]={0};
	scanf("%s", line);
	l = strlen(line);
	boy = line[0];
	for(i=0;i<l;i++)
		if(line[i]!=boy){
			girl = line[i];
			break;
		}
    for(i=0;i<l;i++)
		for(j=i;j<l;j++){
			if(line[i]==boy&&line[j]==girl){
				for(m=i+1;m<j;m++)
					if(line[m]!='0')
						n++;
				if(n==0){
				    numb[k] = i;
				    numg[k] = j;
				    k++;
				    line[i] = '0';
				    line[j] = '0';
				    if(line[0]!='0')
			            i=0;
				}
				n=0;
			}
		}
	for(i=0;numg[i]!=0;i++)
		printf("%d %d\n", numb[i], numg[i]);
	return 0;
}


void match( char child[] , int l )
{
	for ( int i = 0 ; i <= l ; i++ )
		if ( child[i] == child[0] )//if he is a boy
		{
			for ( int j = i + 1 ; j <= l ; j++ )
			{
				if ( child[j] == child[0] )//if the next one is a boy
					break ;
				else if ( child[j] != child[0] && child[j] != '\0' )//if the next one is a girl
				{
					child[i] = child[j] = '\0' ;//let them go
					cout << i << " " << j << endl ;//cout
					match ( child , l ) ;//once again
				}
			}
	}
	return ;
}
int main()
{
	char child[101] ;
	cin.getline( child ,101 ) ;
	match( child , strlen( child ) ) ;

	return 0 ;
}


int len,k,m,t;
    char str[101];
int work( int i,int j)
{
if( i == 0 && j == len-1   )
{printf("%d %d",i,j);
return 0;}
else if( str[i] != str[j] && str[i]!= ' ' && str[i] != ' ')
{
  printf( "%d %d\n",i,j );
  str[i]= ' ';str[j] = ' ';
  for( k = i-1;;k-- )
  {if( str[k]!=' ' )break;}
  for( m = j+1;;m++ )
  {if( str[m]!=' ' )break;}
  work( k,m );

}
else if( str[i] == str[j] && str[i]!= ' ' && str[i] != ' ')
 {   for( t = j+1;t<len;t++ )
     {if( str[t]!=' ' )break;}
     work(j,t);
 }
}
int main()
{

    int i , j ;
    gets(str);
    len = strlen( str );
    work( 0 ,1);
}


int Boy[100],Girl[100],BoyNum,GirlNum;
char Boychar;
void function(int);
int main()
{
 BoyNum=1;
 GirlNum=0;
 Boy[BoyNum]=0;
 Boychar=cin.get();
 function(1);
 return 0;
}
void function(int p)
{
 char c;
 c=cin.get();
 if(c=='\n')
  return;
 else
  if(c==Boychar)
  {
   Boy[BoyNum]=p;
   BoyNum++;
   GirlNum++;
   function(p+1);
  }
  else
  {
   Girl[GirlNum]=p;
   cout<<Boy[GirlNum]<<" "<<Girl[GirlNum]<<endl;
   GirlNum--;
   BoyNum--;
   function(p+1);
  }
}


int len;
char a, b;
char ren[100];
void run(char ren[100])
{
	int i, j;
	for (i = 0; i < len; i++)
		if (ren[i] == b)
		{
			for (j = i - 1; j >= 0; j--)
				if(ren[j] == a)
				{
					cout << j << " " << i << endl;
					ren[i] = 0;
					ren[j] = 0;
					break;
				}
		}
}
int main()
{
	cin.getline(ren,100);
	len = strlen(ren);
	a = ren[0];
	b = ren[len - 1];
	run(ren);
	return 0;
}


char str[100];
int sex[100]={0}, flag[100]={0};
int requeue(int n)
{
	if(n==0)
	return 0;
    int i, t, l;
	for(i=0;i<n-1;i++)
	{
		if(sex[i]==0 && sex[i+1]==1)
		{
			cout<<i+flag[i]<<" "<<i+1+flag[i+1]<<endl;
			if(i==n-2)
			break;
			else
			{
    			for(t=i+2; t<n; t++)
    			{
    				sex[t-2]=sex[t];
    				flag[t]+=2;
    			}
    			for(t=i;t<n-2;t++)
    			{
                    flag[t]=flag[t+2];
                }
			    break;
            }
		}
	}
	return requeue(n-2);
}
int main()
{
	int j, len;
	cin.getline(str,100);
	len=strlen(str);
	for(j=1; j<len; j++)
	{
		if(str[j]==str[0])
		    sex[j]=0;
		else sex[j]=1;
	}
	requeue(len);
	return 0;
}


typedef struct
{
	int boy;
	int girl;
}OUT;

void main()
{
	OUT out[50];
	void sort(OUT *out,int k);
	int i,j,k = 0,len;
	char queue[101],boy,girl;

	gets(queue);
	len = strlen(queue);
	boy = queue[0];
	girl = queue[len - 1];

	while(1)
	{
		for(i = 0;i<len - 1;i++)
		{
			if(queue[i]==boy)
			{
				for(j = i + 1;queue[j]==0;j++);
				//????????
				if(queue[j]==girl)
				{
					queue[i] = 0;
					queue[j] = 0;
					out[k].boy = i;
					out[k].girl = j;
					k++;
					i = j;
				}
				else
					i = j - 1;
			}
		}
		if(k==len/2)
			break;
		//????len/2????????
	}

	sort(out,k);
	//???????
	for(i = 0;i<k;i++)
		printf("%d %d\n",out[i].boy,out[i].girl);
}

void sort(OUT *out,int k)
{
	int i,j,min,minum;
	OUT temp;
	for(i = 0;i<k-1;i++)
	{
		min = out[i].girl;
		minum = i;
		for(j = i + 1;j<k;j++)
		{
			if(min>out[j].girl)
			{
				min = out[j].girl;
				minum = j;
			}
		}
		if(minum - i)
		{
			temp = out[i];
			out[i] = out[minum];
			out[minum] = temp;
		}
	}
}


char s[255],b;

void solve(int l, int r)
{
int c=0, i=l+1, j=l+1;
while (i<r-1) {
  do {
    if (s[i++]==b) c++; else c--;
  } while (c>0);
  solve(j,i-1);
  j=i;
}
printf("%d %d\n", l, r);
}

int main()
{
int l;
scanf("%s", s);
b=s[0];
l=strlen(s)-1;
if (l%2 == 0) l--;
solve(0, l);
return 0;
}


int main ()
{
	char str[100],a,b;
	cin >> str;
	int len,i,j;
	len = strlen(str);
	a = str[0];
	b = str[len - 1];
	for (i = 0;i < len;i++)
		for (j = i - 1;j >= 0;j--)
		{
			if (str[i] == b && str[j] == a)
			{
				cout << j << ' ' << i << endl;
				str[j] = b;
				break;
			}
		}
	return 0;
}


char b,g,chr[100];
struct
	{
		int num,t;
		char s;
	}ch[100];

void chulie(int a)
{
	int k,m,n;
	if ((ch[a].s==g) && ch[a].t!=0 )
	{
		for (k=a-1;k>=0;k--)
		{
			if (ch[k].s==b && ch[k].t!=0)
			{
				printf("%d %d\n",ch[k].num,ch[a].num);
				ch[k].t=0;
				ch[a].t=0;
				break;
			}
		}
	}
	if (chr[a+1]!='\0')
		chulie(++a);
}
int main()
{

	int nb,ng,i,j,k,l,m;
	scanf("%s",chr);
	b=chr[0];
	for (i=0;chr[i]!='\0';i++)
	{
		ch[i].num=i;
	    ch[i].t=1;
		ch[i].s=chr[i];
	}
	for (i=0;chr[i]!='\0';i++)
	{
		if (chr[i]!=b)
		{
			g=chr[i];
			break;
		}
	}
	chulie(i);
	return 0;
}


int flag = 0;
void f(int i, int j, char str[], char ch)
{
	if (flag == 1)
	{
		return;
	}
	if (i < 0)
	{
		f(j, j + 1, str, ch);
	}
	if (str[i] == str[0])
	{
		if (str[j] == ch)
		{
			cout << i << " " << j << endl;
			if (str[j + 1] == '\0')
			{
				flag = 1;
			}
			str[i] = str[j] = ' ';
			f(i - 1, j + 1, str, ch);
		}
		else
		{
			f(j, j + 1, str, ch);
		}
	}
	else
	{
		f(i - 1, j, str, ch);
	}
}
int main()
{
	char str[200], ch;
	int i, a = 0;
	cin >> str;
	for (i = 0; str[i] != '\0'; i++)
	{
		if (str[i] != str[0])
		{
			ch = str[i];
			f (i - 1, i, str, ch);
			return 0;
		}
	}
}


char a[1000];
int n;

int xx (int k)
{
     int x,y;
     x=k;
     y=k+1;
     while (a[y]==a[x])
     y=xx(y);
     cout <<x<<" "<<y<<endl;
     return y+1;
}

int main ()
{
    cin.getline(a,999,'\n');
    n=strlen(a);
    xx(0);
    return 0;
}


void pair(char [],int,int);
int main()
{
	int len,t;
	char s[100];
	scanf("%s",s);
	len=strlen(s);
	t=0;
	pair(s,len,t);
	return 0;
}
void pair(char s[],int len,int t)
{
	int i,j,count=0;
	i=1;
	if(t==len-2)
		{
			printf("0 %d\n",len-1);
			return;
		}
	while(s[i]==s[0]||s[i]==' ')
	{
		i++;
	}
	for(j=i-1;s[j]==' ';j--)
		count++;
	printf("%d %d\n",i-count-1,i);
	s[i-count-1]=' ';
	s[i]=' ';
	pair(s,len,t+2);
}


int main()
{
	char child[100],a;
	cin >>child;
	a=child[0];
	int i=0,j=0;
	while (child[0]!=0)
	{
		if (child[i]!=a&&child[i]!=0)
		{
			for (j=i-1;j>=0;j--)
				if (child[j]==a)
				{
					cout <<j <<" " <<i <<endl;
					child[i]=0;
					child[j]=0;
					break;
				}
		}
	    i++;
	}

	return 0;
}


char boy,girl;
int len=0;
/*void take_hand(char a[],int i)
{
     if(i==len-1)
     {
       cout<<0<<" "<<len-1;
       return ;
     }
     if(a[i]=='o')
     {
        take_hand(a,i+1);
     }
     if(a[j]==girl)
     {
         cout<<i<<" "<<j<<endl;
         a[i]='o';
         a[j]='o';
     }
     else if(a[j]==boy)
     {
          take_hand(a,j);
     }
     else
     j++;
}*/
int main()
{
    char a[100]={0};
    cin>>a;
    len = strlen(a);
    boy=a[0];
    for(int i=0;i<100;i++)
    {
       if(a[i]!=boy)
       {
          girl = a[i];
          break;
       }
    }
    //take_hand(a,0);
    for(int i=0;i<len-1;i++)
    {
            if(a[i]==girl)
            {
                for(int j=i-1;j>0;j--)
                {
                        if(a[j]==boy)
                        {
                            cout<<j<<" "<<i<<endl;
                            a[j]='\0';
                            break;
                        }
                }
            }
    }
    cout<<0<<" "<<len-1<<endl;

    return 0;
}


int l=0;
int main()
{
	int i;
	int count=0;
	char c[100]={"\0"};
	int out(char c[]);
	cin.getline(c,100);
	for (i=0;c[i]!='\0';i++)
		count++;
	l=count;
	out(c);
	return 0;
}
int out(char c[])
{
	int count=0;
	int i,j;
	for (i=0;c[i]!='\0';i++)
		count++;
    if (l==0)
		return 0;
	else
	for (i=0;i<count;i++)
	{
		if (c[i]==c[count-1])
		{
			for (j=i-1;j>=0;j--)
			{
				if (c[j]=='1')
					continue;
				if (c[j]==c[count-1])
				{
					break;
				}
				if (c[j]==c[0])
				{
					cout<<j<<' '<<i<<endl;
					c[i]='1';
					c[j]='1';
					l=l-2;
					break;
				}
			}
		}
	}
	out(c);
}


void f(int n,int *a,char *b,char boy, char girl)
{
     int i;
     if(n==2)printf("%d %d\n",*a,*(a+1));
     else
     {
         for(i=0;i<n;i++)
         {
                         if(*(b+i)==boy&&*(b+i+1)==girl)
                         {
                              printf("%d %d\n",*(a+i),*(a+i+1));
                              break;
                         }
         }

         for(;i<n-2;i++)
         {
         *(a+i)=*(a+i+2);
         *(b+i)=*(b+i+2);
         }
         f(n-2,a,b,boy,girl);
     }
}

int main()
{
    int a[1000],geshu,i;
    char b[1000];
    char boy,girl;
    gets(b);
    geshu=strlen(b);
    for(i=0;i<geshu;i++)a[i]=i;
    boy=b[0];
    girl=b[geshu-1];
    f(geshu,a,b,boy,girl);
}


	char str[101];
int test(int num,char sex)
{
	if(str[num]!='\0')
	{
		if(str[num]==sex) test(num+1,sex);
		else
		{
			int i=0;
			for(i=num-1;i>=0;i--)
			{
				if(str[i]==sex)
				{
			 	cout<<i<<" "<<num<<endl;
				str[i]='!';
				 str[num]='!';
				 break;
				}
			}
		}
		test(num+1,sex);
	}
	else return 0;
}
int main()
{
	cin.getline(str,101);
	char boy=str[0];
	test(1,boy);
	return 0;
}


void main ()
{
	char ch[100];
	char male;
	int i;
	int len;

	gets(ch);
	len=strlen(ch);
	male=ch[0];
    for (i=1;i<len;i++)
	{
		if (ch[i]!=male)
		{
			int j=i;
			int n1=0,n2=0;

			for (;j>-1;j=j-1)
			{
				if(n1==n2&&ch[j-1]==male) {printf("%d %d\n",(j-1),i);break;}
				if(ch[j-1]==male) n1++;
				else n2++;
			}
		}
	}
}


int main()
{
	char str[110]={0};
	int i=0;
    cin>>str;
	int n,j=0;
	n=strlen(str);
	for(i=0;i<=n;i++)
	{
		if(str[i]!=str[0])
		{
			str[i]=0;
			for(j=i;j>=0;j--)
			{
				if(str[j]==str[0])
				{
					str[j]=0;
					cout<<j<<" ";
					break;
				}
			}
			cout<<i<<endl;
		}
	}

		return 0;
}


void kuohao (char str[],int x);
int lenth;
char c;
int main()
{
    char a[10000];
    cin>>a;
    lenth=strlen(a);
    c=a[0];
    kuohao(a,1);
return 0;
}
void kuohao(char str[],int x)
{
  if(x<lenth)
  {
      if(str[x]!=c)
      {
         int i=x-1,zuo=0,you=0;
         while(1)
         {
           if(str[i]==c)
                zuo++;
           else
                 you++;
           if(zuo==you+1)
              break;
           i--;
         }
         cout<<i<<" "<<x<<endl;
         kuohao(str,x+1);
      }
       else
          kuohao(str,x+1);
  }
}


char str[200 + 1];
int length ,sum , i;
int flag[100 + 1];
char p , q;

void f(char s[] ,int k);

int main()
{
	int  j;
	cin >> str;

	length = strlen(str);
	p = str[0];
	q = str[length - 1];
	j = 0;
	for( i = 1 ;i <= length -1 ; i++)
		if(str[i] == q)
		{
		    j ++;
			flag[j] = i;
		}
	sum = j;
	f(str,1);
	return 0;
}
void f(char s[],int k)
{
	if(k <= sum)
	{
		for(i = flag[k] ; i >= 0 ; i --)
		{
			if(s[i] == p)
			{
				printf("%d %d\n",i,flag[k]);
				s[i] ='\0';
				s[flag[k]] = '\0';
				break;
			}
		}
		f(s,k+1);
	}
	else
		return;
}


char a[101],x,y;int len;
void find(int t)
{
	int j;
	if(t==2)
	{
		for(int i=0;i<len;i++)
		{
			if(a[i]==x)
				cout<<i;
			else if(a[i]==y)
				cout<<' '<<i<<endl;
		}
	}
	else if(t>2)
	{
		for(int i=0;i<len-1;i++)
			if(a[i]==x)
			{
			    j=1;
				while((i+j<len)&&(a[i+j]==' '))
					j++;
				if(a[i+j]==y)
					{
						cout<<i<<' '<<i+j<<endl;
						a[i]=' ';
						a[i+j]=' ';
						find(t-2);
						return;
				    }
			}
	}
return;
}
int main()
{
	int i;
	cin>>a;
	len=strlen(a);
	x=a[0];
	for(i=1;i<len;i++)
		if(a[i]!=x)
		{
			y=a[i];
			break;
		}
	find(len);
return 0;
}


int main()
{
	char input[101],boy,girl;
	int dui[101]={0},i=1,j;
	cin.getline(input,101,'\n');
	boy=input[0];
	while(input[i]==boy)
		i++;
	girl=input[i];
	for(i=0;input[i]!=0;i++)
	{
		if(input[i]==boy)
			dui[i]=1;
		if(input[i]==girl)
			dui[i]=2;
	}
	for(i=0;dui[i]!=0;i++)
	{
		if(dui[i]==2)
		{
			for(j=i-1;dui[j]!=1;j--);
			cout<<j<<" "<<i<<endl;
			dui[j]=0;
			dui[i]=0;
		}
	}
	return 0;
}


char queue[100];
int main ()
{
	cin >> queue;
	int len = strlen(queue), i, j, temp;
	for (i = 0; i < len - 1;)
	{
		if (queue[len - 1] == ' ')
			break;
		if (queue[i] != ' ')
		{
			if (queue[i + 1] == queue[i])
			{
				i++;
				continue;
			}
			else if (queue[i + 1] == ' ')
			{
				j = i + 1;
				while(queue[j] == ' ')
					j++;
				if (queue[j] != queue[i])
				{
					cout << i << " " << j << endl;
					queue[i] = queue[j] = ' ';
					if (i == 0)
						continue;
					temp = i - 1;
					while (queue[temp] == ' ')
						temp--;
					i = temp;
				}
				else
					i = j;
			}
			else
			{
				if (queue[i] == queue[0])
				{
					cout << i << " " << i + 1 << endl;
					queue[i] = ' ';
					queue[i + 1] = ' ';
					if (i == 0)
						continue;
					temp = i - 1;
					while (queue[temp] == ' ')
						temp--;
					i = temp;
				}
			}
		}
		else
		{
			i++;
			continue;
		}
	}
	return 0;
}


//#define B '('
//#define G ')'
int main(int argc, char* argv[])
{
	char s[N], e[N], B, G;
 int i,k;
 gets(s);
B = s[0];
 for(i=0;s[i];i++)e[i]='a';

i=0;
while(s[i])
{if(s[i]==B)i++;
 else{
   for(k=i-1;k>=0;k--)
    if(s[k]==B && e[k])
    {e[k]='\0';
     printf("%d %d\n",k,i);
     break;
     }
   i++;
  }
}
puts("\n");
return 0;
}


char input[100];//?????
int lidui[100];//?????????1?????0?????
int boynum[100];//i???????boynum[i]??????
void boysAndGirls ( char boy , int pos , int dis , int charlong )//boy?????????pos????????dis??????????dis????????charlong??????????
{
	if(dis == charlong) boynum[charlong-1] = 0;//????????????????????
	else
	{
		if(lidui[pos] == 1              //????????
				|| input[pos] == boy       //???????
				|| pos<dis                 //????????
				|| lidui[pos-dis] == 1 )//?????????????????
			boysAndGirls ( boy , pos+1 , dis , charlong );//??????????
		else
		{
			if(pos >= charlong - 1)
				boysAndGirls ( boy , 0 , dis+1 , charlong );//???????????????????
			else
			{
				if( input[pos-dis] != boy )//???????dis?????
					boysAndGirls ( boy , pos + 1 ,dis , charlong );//??????????
				else
				{
					boynum[pos] = pos - dis;//???????pos-dis?????
					lidui[pos] = 1;  lidui[pos - dis] = 1;//???????????
					boysAndGirls ( boy , pos + 1 , dis , charlong );//???????????
				}
			}
		}
	}
}
int main()
{
	int i,charlong ;
	char boy;
	cin >> input;
	boy = input[0];//?????????????
	charlong=strlen(input);
	boysAndGirls ( boy , 0 , 1 , charlong );//?????????
	for( i=0 ; i < charlong ; i++ )//??????
	{
		if( i == charlong - 1 )  cout <<"0 "<< charlong - 1;
		else
		{
			if( boynum[i] == 0 ) continue;
			else cout << boynum[i] << " " << i << endl;
		}
	}
	cin.get();cin.get();cin.get();cin.get();cin.get();cin.get();cin.get();
	return 0;
}


int boy=0,children[100][2];
int childnum=0;
int theboy;
void findpair(char boysign)
{
	if(boy==-1)
		return;
	char sign;
	cin>>sign;
	if(sign==boysign)
	{
		boy++;
		childnum++;
		children[childnum][0]=0;
		findpair(boysign);
		return;
	}
	else
	{
		childnum++;
		children[childnum][0]=1;
		for(int i=childnum; ;i--)
			if(children[i][0]==0&&children[i][1])
			{
				theboy=i;
				children[i][1]=0;
				break;
			}
		cout<<theboy<<' '<<childnum<<endl;
		boy--;
		findpair(boysign);
		return;
	}
}
int main()
{
	for(int i=0;i<100;i++)
	    children[i][1]=1;
	char boysign;
	cin>>boysign;
	findpair(boysign);
	return 0;
}


int main()
{
	int numl[51];
	int pl=0;
	char str[101];
	cin.getline(str,101);
	int len=strlen(str);
	for(int i=0;i<len;i++)
	{

		if(str[i]==str[0])
		{
			numl[pl]=i;
			pl++;
		}
		else if(str[i]!=str[0])
		{
			cout<<numl[pl-1]<<" "<<i;
cout<<endl;
			pl--;
		}
	}

	return 0;
}


/*
 * qimomoni_2.cpp
 *	????
 *  Created on: 2011-1-8
 *      Author: ???
 */

int Try(int i,char boy){
	char a;
	int b;
	cin.get(a);
	if(a!=boy)
		return i;
	else
	{
		b=Try(i+1,boy);
		cout<<i<<' '<<b<<endl;
		return Try(b+1,boy);
	}
}
int main(){
	int i=0;
	int b;
	char boy;
	cin>>boy;
	b=Try(i+1,boy);
	cout<<i<<' '<<b;
	return 0;
}


char a[110];
int l;
void vv(char a[], char b, char g)
{
    int i, flag = 0;
    l = strlen(a);
    for(i = 0; i < l; i++)
        if(a[i] != '*')
        flag = 1;
    if(flag == 0)
        return ;
    else
    {
    for(i = 0; i < l; i++)
    {
        if(a[i] == g)
        {
            for(int j = i - 1; j >= 0; j--)
            if(a[j] == b)
            {
                cout << j << " " << i << endl;
                a[j] = '*';
                a[i] = '*';
                break;
            }

        }
    }
    vv(a, b, g);
    }
}
int main()
{
    char b, g;
    cin >> a;
    l = strlen(a);
    b = a[0];
    g = a[l - 1];
    vv(a, b, g);

    return 0;
}


int main()
{
	int i,j,k,l,count;
	char s[105],head;
	gets(s);
	l=strlen(s);
	count=0;
	for(;;)
	{
		for(i=0;i<l;i++)
		{
			if(s[i]==' ') i++;
			else
			{
				head=s[i];
				break;
			}
		}
		for(j=i;j<l;j++)
		{
			if(s[j]!=' '&&s[j]!=head)
			{
				for(k=j-1;k>=0;k--)
				{
					if(s[k]!=' ') break;
				}
				printf("%d %d\n",k,j);
				s[k]=' ';s[j]=' ';
			}
		}
		count+=2;
		if(count==l) break;
	}
	return 0;
}


void main()
{
	char quene[500]={'\0'},boy,girl;
	int i,n,g=0,pair;
	gets(quene);
	n=strlen(quene);
	pair=n/2;
	boy=quene[0];
	for(i=0;i<n;i++)
	{
		if(quene[i]!=boy)
		{
			girl=quene[i];
			break;
		}
	}
	while(pair>0)
	{
		for(i=g;i<n;i++)
		{
			if(quene[i]==girl)
			{
				g=i;
				break;
			}
		}
		for(i=g;i>=0;i--)
		{
			if(quene[i]==boy)
			{
				printf("%d %d\n",i,g);
				pair--;
				quene[i]='a';
				quene[g]='a';
				break;
			}
		}
	}
}


int a[100], n, flag = 0;
char str[100], x, y;
void paidui(int n)
{
	int i = 0;
	for (; i < n;i++)
	{
		if (str[a[i]] == x && str[a[i + 1]] == y)
		{
			cout << a[i] << ' ' << a[i + 1] << endl;
			break;
		}
	}
		for (; i < n - 2; i++)
			a[i] = a[i + 2];
		if (n - 2 >= 2)
			paidui(n - 2);
}
int main ()
{
	cin.getline (str,100);
	n = strlen(str);
	x = str[0];
	for(int i = 0; i < n; i++)
	{
		if (str[i] != x)
		{
			y = str[i];
		    flag = 1;
		}
		if (flag == 1)
			break;
	}
	for (int i = 0; i < n; i++)
		a[i] = i;
	paidui(n);
	return 0;
}


int i=0;
char boy,girl;
void search(char a[])
{
	int j=0,k,bo,gi;
	if(a[0]!='.')
	{
		while(a[j]!=girl)
			j++;
		k=j-1;
		gi=j;
		a[gi]='.';
		while(a[k]=='.')
			k--;
		a[k]='.';
		bo=k;
		cout<<bo<<" "<<gi<<endl;
		search(a);
	}
}
int main()
{
	char a[100];
	cin.getline(a,100);
	while(a[i]!='\0')i++;
	boy=a[0];
	girl=a[i-1];
	search(a);
	return 0;
}


int main()
{
	char c[108];
	int l;
	char key;
	int i, j;
	int a[100];
	int count = 0;

	cin >> c;

	l = strlen(c);
	key = c[0];

	for(i = 0; i < l; i ++)
	if(c[i] != key)
	{
		a[count] = i;
		count ++;
	}

	for(i = 0; i < l / 2; i ++)
	{
		for(j = a[i]; j >= 0; j --)
			if(c[j] == key)
			{
				cout << j << " " << a[i] << endl;
				c[j] = key + 1;
				break;
			}
	}

	return 0;
}


//shu ru fa huai le bu xie zhu shi le = =!
int main()
{
	char str[100];
	cin.getline(str,101);
	int i,j,k,t=0;
	int number[51][2];
	int n=0;
	while(true)
	{
		if(str[n]=='\0')
			break;
		n++;
	}
	for(i=0;i<n-1;i++)
	{
		if(str[0]=='\0')
			break;
		if(str[i]==str[0])
		{
			for(j=i+1;j<n;j++)
			{
				if(str[j]!=str[0])
				{
					for(k=j;k>=0;k--)
					{
						if(str[k]==str[0])
							break;
					}
					str[j]=str[k]='\0';
					number[t][0]=k;
					number[t++][1]=j;
				}
			}
		}
	}
	int d;
	for(i=0;i<t-1;i++)
	{
		for(j=i+1;j<t;j++)
		{
			if(number[i][1]>number[j][1])
			{
				d=number[i][1];number[j][1]=number[i][1];number[i][1]=d;
				d=number[i][0];number[j][0]=number[i][0];number[i][0]=d;
			}
		}
	}
	for(i=0;i<t;i++)
	{
		cout<<number[i][0]<<" "<<number[i][1]<<endl;
	}
	return 0;
}


void queue(char[],int);
char boy,girl;
int main()
{
	char str[100];
	cin.getline(str,100);
	int l=strlen(str);
	boy=str[0];
	for(int i=1;i<l;i++)
	{
		if(str[i]!=boy)
		{
			girl=str[i];
			break;
		}
	}
	for(int i=0;i<l;i++)
	{
	  queue(str,l);
	}
	return 0;
}
void queue(char a[],int s)
{

	for(int i=0;i<s;i++)
	{
		if(a[i]==boy)
		{
			int k=1;
			while(a[i+k]=='0'){k++;}
			if(a[i+k]==girl)
			{
				cout<<i<<" "<<i+k<<endl;
				a[i]='0';
				a[i+k]='0';
				break;
			}
		}
	}
}


void fun(char, int);
char a, b;
char s[100];
int main()
{
	int n, i;
	cin >> s;
	n = strlen(s);
	a = s[0];
	b = s[n - 1];
	for(i = 0; i < n; i++)
	{
		fun(s[i],i);
	}
	return 0;
}
void fun(char c, int i)
{
	int k, j = 0;
	if(c == a)
		return;
	else
	{
		for(k = 1;; k++)
		{
			if(s[i - k] == a)
			{
				if(j == 0)
				{
				    cout << i - k << " " << i << endl;
					break;
				}
				else
					j--;
			}
			else
				j++;
		}
	}
	return;
}


void main()
{
	char a[100];
	gets(a);
	int length=strlen(a);
	int i,j;
	int w1,w2;
	char q;
	q=a[0];
	for(i=0;i<length;i++){
		if(a[i]==q){
			for(j=i+1;j<length;j++){
				if(a[j]==' '){
					continue;
				}
				else if(a[j]==q){
					i=j-1;
					break;

				}
				else if(a[j]!=q&&a[j]!=' '){
					printf("%d %d\n",i,j);
					a[i]=' ';
					a[j]=' ';
					i=-1;
					break;
				}
			}
		}
	}
}


int main()
{
	char a[110],c,d;
	int i,j,flag,flag1;
	gets(a);
	c=a[0];d=a[strlen(a)-1];
	do
	{
		  flag=0;flag1=0;
		     for(i=0;i<(strlen(a)-1);i++)
			 {
		     	if(a[i]!=1)
				{flag=1;break;}
			 }
			for(i=0;i<(strlen(a)-1);i++)
			{	if(a[i]!=c)
					continue;
				  for(j=i+1;a[j]!=c && j<(strlen(a));j++)
				  {
					  if(a[j]==d)
					{	printf("%d %d\n",i,j);
					   a[j]=1;
					   a[i]=1;
					   flag1=1;
					}
					  if(flag1)
						  break;
				  }
					if(flag1)
						break;
			}
	}
	while(flag);
		return 0;
}


struct children{
	char sex;
	int num;
};
int main()
{
	char line[100];
	int n,m;
	int i,j,k;
	struct children pig[100];
	scanf("%s",line);
	n=strlen(line);
	for(i=1;i<n-1;i++)
	{
		if(line[i]==line[0])
			line[i]='(';
		else
			line[i]=')';
	}
	line[0]='(';
	line[n-1]=')';
	for(i=0;i<n;i++)
	{
		pig[i].num=i;
		pig[i].sex=line[i];
	}
	m=n;
	for(i=0;i<(n/2-1);i++)
	{
		for(j=0;j<m;j++)
		{
			if(pig[j].sex=='('&&pig[j+1].sex==')')
			{
				printf("%d %d\n",pig[j].num,pig[j+1].num);
				k=j;
				for(j;pig[m-3].num!=n-1;j++)
				{
					pig[j]=pig[j+2];
				}
				m-=2;
				break;
			}
		}
	}
	printf("%d %d\n",0,n-1);
	return 0;
}


char girl;
int main()
{
	void Match(char queue[], int p);
	char queue[100 + 10];
	cin.getline(queue, 101);
	girl = queue[strlen(queue) - 1];
	Match(queue, 0);
	return 0;
}

void Match(char queue[], int p)
{
	int q = p;
	do
	{q++;} while(queue[q] == 0);
	if (queue[q] == girl)
	{
		cout << p << " " << q << endl;
		queue[p] = 0;
		queue[q] = 0;
		do
		{p --; if (p < 0) break;}
		while(queue[p] == 0);
		if (p >= 0)
			Match(queue, p);
	}
	else Match(queue, q);
}


char a[10000];
int use[10000]={0};
void f(int len)
{
	int i,j;
	for(i=0;i<len;i++)
		if(a[i]==a[len-1]&&use[i]==0)
		{
			for(j=i-1;j>=0;j--)
				if(a[j]==a[0]&&use[j]==0)
				{
					cout<<j<<" "<<i<<endl;
					use[i]=1;
					use[j]=1;
					break;
				}
		}
}
int main()
{
	int len;
	cin>>a;
	len=strlen(a);
	f(len);
	return 0;
}


char b, g, a[100];
int len;

int paidui(int n)
{
	for (int i = n; i < len; i++)
	{
		if (a[i] == '*') continue;
		if (a[i] == b)
		{
			a[i] = '*';
			int k = paidui(i + 1);
			cout << i << ' ' << k << endl;
		}
		else if (a[i] == g)
		{
			a[i] = '*';
			return i;
		}
	}
}

int main()
{
	cin.getline(a, 100);
	len = strlen(a);
	b = a[0];
	g = a[len - 1];
	paidui(0);

	return 0;
}


int u=0;
void prin(char a[],int l)
{
	int i,j;
	for(i=0;i<l;i++)
	{
		if(a[i]=='\0')
			continue;
		for(j=i+1;j<l;j++)
		{
			if(a[j]=='\0')
				continue;
			if(a[j]!=a[i])
			{
				printf("%d %d\n",i,j);
				a[i]='\0';
				a[j]='\0';
				u++;
				break;
			}
			if(a[j]==a[i])
				break;
		}
		if(a[j]!='\0')
			continue;
		if(a[j]=='\0')
			break;
	}
	if(u!=l/2)
		prin(a,l);
}

void main()
{
	char a[100];
	int l;
	gets(a);
	l=strlen(a);
	prin(a,l);
}


int data(char *c,int i,char boy,char girl){
	if(*(c+i)==0)return 0;
	if(*(c+i)==girl)return i;
	int j;
	j=data(c,i+1,boy,girl);
	cout<<i<<' '<<j<<endl;
	return data(c,j+1,boy,girl);
}
int main(){
	char children[1000],boy,girl;
	int i;
	cin>>children;
	boy=children[0];
	for(i=0;children[i]!=0;i++){
		if(children[i]!=boy){
			girl=children[i];
			break;
		}
	}
	i=data(children,0,boy,girl);
	return 0;
}


int pos;

void match(char lch)
{
    int spos = pos;
    char ch;
    pos++;
    scanf("%c", &ch);
    while (ch == lch)
    {
        match(ch);
        pos++;
        scanf("%c", &ch);
    }
    printf("%d %d\n", spos, pos);
}

int main()
{
    char ch;
    pos = 0;
    scanf("%c", &ch);
    match(ch);
    return 0;
}


int main()
{
    char str[120], *p;
    p = str;
    int boy[100];
    cin >> str;
    int m = 0, bo = 0;
    while(*p != 0)
    {
        if(*p == str[0])
        {
            bo++;
            boy[bo] = m;
        }
        else
        {
            cout << boy[bo] << " " << m << endl;
            bo--;
        }
        p++;
        m++;
    }
}


void lashou(char [],int ,int );
int main()
{
	int i,sum;
	char nn[101];
	cin.getline(nn,101);
	for(i=1;nn[i]!='\0';i++)
	{
		if(nn[i]==nn[0]) continue;
		else
		{
			sum=nn[0]+nn[i];
		}
	}
	i--;
	lashou(nn,i,sum);
	return 0;
}
void lashou(char shou[],int n,int sum)
{
	int i,j,k,zhi;
	for(i=0;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			if((shou[i]+shou[j])==sum)
			{
				zhi=0;
				for(k=i+1;k<=j-1;k++)
				{
					if(shou[k]!=0) zhi=1;
				}
				if(zhi==0)
				{
				cout<<i<<" "<<j<<endl;
				shou[i]=shou[j]=0;
				lashou(shou,n,sum);
				break;
				}
			}
		}
	}
}


void zhaodui(char str[]);
int main()
{
	char str[100];
	cin.getline(str,100,'\n');
	zhaodui(str);
	return 0;
}
void zhaodui(char str[])
{
	char nan[2],nv[2];
	char str1[100];
	int i,j;
	strcpy(str1,str);
	nan[0]=str[0];
	for(i=0;i<99;i++)
	{
		if(str[i]!=str[0])
		{
			nv[0]=str[i];
			break;
		}
	}
	for(j=0;j<99;j++)
	{
		for(i=1;i<98;i=i+2)
		{
			if(str[j]==nv[0]&&str[j-i]==nan[0])
			{
				cout<<j-i<<" "<<j<<endl;
				str[j]='\0';
				str[j-i]='\0';
			}
		}
	}
}


void move(char c[],int a[], int pos, int n);
void f(char c[],int n, int a[]);
int main()
{
	char c[100];
	int  i, n, a[100] = {0};
	cin >> c;
	n = strlen(c);
	for(i = 0;i < n;i++)
		a[i] = i;
	f(c,n,a);
	return 0;
}
void move(char c[], int a[], int pos, int n)
{
	int i;
	for(i = pos;i < n - 2;i++)
	{
		c[i] = c[i+2];
		a[i] = a[i+2];
	}
}
void f(char c[],int n,int a[])
{
	int i = 0;
	for(i = 0;i < n;i++)
		if(c[i] == c[0] && c[i+1] == c[n-1])
		{
			cout << a[i] <<' '<< a[i+1] <<endl;
			move(c,a,i,n);
			f(c,n-2,a);
			break;
		}
}


void out(char s[],int a[],char boy,int len)
{
	int i,k;
	if(len==2)
		cout<<a[0]<<' '<<a[1]<<endl;
	else
	{
		for(i=0;i<len-1;i++)
			if(s[i]==boy&&s[i+1]!=boy)
			{
				cout<<a[i]<<' '<<a[i+1]<<endl;
				for(k=i;k<len-2;k++)
				{
					s[k]=s[k+2];
				    a[k]=a[k+2];
				}
				out(s,a,boy,len-2);
				break;
			}
	}
	return;
}
int main(){
	char s[100];
	cin>>s;
	int a[100],i;
	int len=strlen(s);
	for(i=0;i<100;i++)
		a[i]=i;
	char boy=s[0];
	out(s,a,boy,len);
    return 0;
}


char line[101];
void main()
{
	int i,j;
	scanf("%s",line);
	char boy=line[0];
	for(i=1;i<strlen(line);i++)
	{
		if(line[i]==boy)
			continue;
		else if(line[i]!=' ')
		{
			for(j=i-1;j>=0;j--)
			{
				if(line[j]==boy)
				{
					printf("%d %d\n",j,i);
					line[j]=line[i]=' ';
					break;
				}
			}
		}
	}
}


int flag[101]={0};
char str[101],boy,girl,num=0;
void match(int i)
{
	flag[i]=1;
	for(int k=i;;k--)
		{
			if(str[k]==boy&&flag[k]==0)
			{
			   cout<<k<<' '<<i<<endl;
			   flag[k]=1;
			   break;
			}
		}
	num=num+2;
	if(num==strlen(str))return;
		for(++i;;i++)
		{
			if(str[i]==girl)
				{
					match(i);
					break;
			}

		}
	return;
}

int main()
{
	cin>>str;
	boy=str[0];
	int i;
	char *p=str;
	for(i=0;;p++,i++)                //i--first girl
	{
		if(*p!=boy)
			{
				girl=*p;
		        break;
		    }
	}
	match(i);
	return 0;
}


int main()
{
	char line[110],boy,girl;
	int b[110],g[110],p=1,s=0,lin[110],mark[110];
	int len;
	for(int i=0;i<=109;i++)
		lin[i]=i;
	cin.getline(line,120,'\n');
	len=strlen(line)-1;
	boy=line[0];
	for(int i=0;i<=len;i++)
		if(line[i]!=boy)
		{
			girl=line[i];
			break;
		}
	while(s<len+1)
	{
		for(int i=0;i<=len-1;i++)
		{
			if(line[i]==boy&&line[i+1]==girl)
			{
				b[p]=lin[i];
				g[p]=lin[i+1];
				p++;
				for(int j=i+2;j<=len;j++)
				{
					line[j-2]=line[j];
					lin[j-2]=lin[j];
				}
				s=s+2;
			}
		}
	}
	for(int i=1;i<=p-2;i++)
		for(int j=1;j<=p-1-i;j++)
			if(g[j]>g[j+1])
			{
				int temp=g[j];
				g[j]=g[j+1];
				g[j+1]=temp;
				temp=b[j];
				b[j]=b[j+1];
				b[j+1]=temp;
			}
	for(int i=1;i<=p-1;i++)
		cout<<b[i]<<" "<<g[i]<<endl;
	return 0;
}


int main()
{
	int stack[5000],top=0,i=0;
	char d;
	char a='X',b='X';
	while ((d=cin.get())!='\n')
	{
		if (a=='X') a=d;
		if (a!=d&&b=='X') b=d;
		if (d==a)
		{
			top++;
			stack[top]=i;
		}
		if (d==b)
		{
			cout<<stack[top]<<' '<<i<<endl;
			top--;
		}
		i++;
	}
	return 0;
}


int main()
{
	char s[101];gets(s);
	struct kid
	{
		char c;
		int num;
	}kid[100];
	int n;
	n=strlen(s);
	int i,j;
	for(i=0;i<n;i++)
	{
		kid[i].c=s[i];
	}
	for(i=0;i<n;i++)
	{
		kid[i].num=i;
	}

	for(i=0;i<n-1;i++)
	{
        if(kid[i].c!=kid[i+1].c)
		{
			printf("%d %d\n",kid[i].num,kid[i+1].num);

			for(j=i;j<n-2;j++)
			{kid[j]=kid[j+2];}
			n-=2;
			i=-1;

		}

	}

return 0;

}


void f(int,char[],char,char);
int tag[100]={0};
int main()
{
	char a[100];
	cin.getline(a,100);
	int l,p;
	l=strlen(a);
	char boy,girl;
	boy=a[0];
	for(int i=0;i<l;i++)
	{
		if(a[i]!=boy)
		{
			girl=a[i];
			p=i;
			break;
		}
	}
	f(p,a,boy,girl);
	return 0;
}
void f(int p,char b[100],char m,char fe)
{
	if(b[p]=='\0') return;
	if(b[p]!=fe) f(p+1,b,m,fe);
	else
	{
		for(int i=p-1;i>=0;i--)
		{
			if(tag[i]==0)
			{
				cout<<i<<" "<<p<<endl;
				tag[i]=1;
				tag[p]=1;
				break;
			}
		}
		f(p+1,b,m,fe);
	}
}


void Q(char a[])
{
	char c;
	c = a[0];
	int pos[100];
	int i = 0, num = 0;
	do
	{
		if (a[i] == c)
		{
			num++;
			pos[num] = i;
		}
		else
		{
			cout << pos[num] << " " << i << endl;
			num--;
		}
		i++;
	}while (i <= strlen(a) - 1);
}
int main()
{
	char children[100];
	cin >> children;
	Q(children);
	return 0;
}


void line(char a[100],int b)
{
	int i,j;
	for(i=0;i<b;i++)
	{
		if(a[i]!=a[0])
		{
			for(j=i;j>=0;j--)
			{
				if(a[j]!=a[i]&&a[j]==a[0])
				{
					cout<<j<<' '<<i<<endl;
					a[j]=a[i]=0;break;
				}

			}}

	}}

int main()
{
	char a[100];
	cin>>a;
	int n;
	n=strlen(a);
	line (a,n);
	return 0;
}


/*bss*/
int stack[MAX], lstack, len;

int main(){
    char c, a=0, b=0;
    int i, j, k;
    while(c=getchar()){
        if(!a) a=c;
        else if (c!=a&&!b) b=c;
        if(c==a) stack[lstack++]=len++;
        else if(c==b) printf("%d %d\n", stack[--lstack], len++);
        else return 0;
    }
}


char c[100];
int match(int x)
{

	int q;
	if(c[x]==c[0])
	{
		q=match(x+1);
		cout<<x<<' '<<q<<endl;
		return match(q+1);
	}
	else
		return x;
}
int main()
{

	cin.getline(c,100);
	match(0);
	return 0;
}


char pos[100];
int po[100] = { 0 };
int len;
char a, b;
void ty(int );
int main()
{
	int i;
	cin.getline( pos, 100);
	a = pos[0];
	len = strlen (pos);
	b = pos[strlen(pos) - 1];
	for( i = 0; i < len; i ++)
	{
		if( pos[i] == a)
			po[i] = 1;
		else
			po[i] = 2;
	}
	ty( 0 );

	return 0;
}
void ty ( int i)
{
	int j = 0;
	if( i == len - 1)
	{
		cout << 0 << " " << i << endl;
		return ;
	}
	else
	{if( po[i] == 2)
		{
		for( j = i - 1; j > 0; j -- )
		{
			if( po[j] == 1)
				break;
		}

			cout << j << " " << i << endl;
			po[j] = 0;
			po[i] = 0;
		}

	ty( i + 1 );
	}
}


char queen[1000];
int main()
{
	cin >> queen;
	int len = strlen(queen);
	char a, b;
	int cnt = 0;
	int boy[1000] = {0};
	a = queen[0];
	b = queen[len - 1];
	for (int i = 0; i < len; i++)
	{
		if (queen[i] == a)
		{
			boy[cnt] = i;
			cnt ++;
		}
		if (queen[i] == b)
		{
			cnt --;
			cout << boy[cnt] << ' ' << i << endl;
		}
	}
	while(EOF!=getchar());
	return 0;
}


/*
 * paiduiyouxi.cpp
 *
 *  Created on: 2010-12-30
 *      Author: qaj
 */
int main() {
	char ch[20000];
	cin >> ch;
	int l = strlen(ch);
	int num[20000];
	for (int i = 0; i < l; i++)
		num[i] = i;
	int n = l;
	char boy, girl;
	boy = ch[0];
	for (int i = 1; i < l; i++) {
		if (ch[i] != boy) {
			girl = ch[i];
			break;
		}
	}
	for (int k = 0; k < l / 2; k++)
		for (int i = 0; i < n; i++) {
			if ((ch[i] == boy) && (ch[i + 1] == girl) || (ch[i] == girl)
					&& (ch[i + 1] == boy)) {
				cout << num[i] << ' ' << num[i + 1] << endl;
				n = n - 2;
				for (int j = i; j < n; j++) {
					ch[j] = ch[j + 2];
					num[j] = num[j + 2];
				}
				break;
			}
		}
	return 0;
}


int leave(int a);

	char str[101];
		int i = 1;

int main()
{

	cin.getline(str, 101);
	leave(0);
	return 0;
}
int leave(int a)
{
	int b;

	if (str[a] == str[0])
	{
		b = leave(a + 1);
		cout << a << " " << b << endl;
		return leave(b + 1);
	}
	else
		return a;
}


char a[101], boy, girl;
int f(int n);
int main()
{
	int i;
	cin.getline(a, 101);
	boy = a[0];
	for (i = 0; a[i] != '\0'; i++)
		girl = a[i];
	f(0);
	return 0;
}
int f(int n)
{
	int i;
	for (i = n; a[i] != '\0'; i++)
	{
		if (a[i] == boy)
		{
			a[i] = '0';
			cout << i << " " << f(i + 1) << endl;
		}
		else if (a[i] == girl)
		{
			a[i] = '1';
			return i;
		}
	}
}


int i = 0,len;
char str[100];
char a;
void P(int d)
{
    while(i < len)
    {
        if (str[i] == a) P(i++);
        else
        {
            cout << d << " " << i << endl;
            i++;
            return;
        }
    }
}

int main()
{
    cin>>str;
    a=str[0];
    len =strlen(str);
    P(0);
    return 0;
}


char line[100];
char boy,girl;
int len;
void queue(int b)
{

	int i=0;
	if(b==len)
		return;
	else
	{
		if(line[b]==girl)
		{
			line[b] = 0;
			for( i=b-1;i>=0;i--)
			{
				if(line[i]==boy)
				{
					cout << i << " " << b << endl;
					line[i]=0;
					break;
				}
			}
	        queue(b+1);
		}
		else
		    queue(b+1);
	}
}
int main()
{
	cin >> line;
    len =strlen(line);
    boy=line[0];
	girl = line[len-1];
	queue(1);
	return 0;
}


void solve(char str[],char m,char f)
{
	int l,flag=1,i,k;
	l=strlen(str);
	for(i=0;i<l;i++)
	{
		if(str[i]==m||str[i]==f)
		{
			flag=0;
			break;
		}
	}
	if(flag) return;
	for(i=0;i<l;i++)
	{
		if(flag==1&&str[i]==f)
		{
			cout<<k<<" "<<i<<endl;
			flag=0;
			str[k]=' ';
			str[i]=' ';
			break;
		}
		if(str[i]==m)
		{
			flag=1;
			k=i;
		}
		if(str[i]==f) flag=0;
	}
	solve(str,m,f);
}
int main()
{
	char str[100],m,f,*p;
	cin.getline(str,100,'\n');
	m=str[0];
	for(p=str;p<str+strlen(str);p++)
	{
		if(*p!=m)
		{
			f=*p;
			break;
		}
	}
	solve(str,m,f);
	return 0;
}


int main()
{
    int stack[100], top = 0, count = 0;
    char boy, c;
    cin >> boy;
    stack[top++] = count++;
    while ((c = cin.get()) != '\n')
    {
        if (c == boy)
        {
            stack[top++] = count++;
        }
        else
        {
            printf("%d %d\n", stack[--top], count++);
        }
    }

    return 0;
}


int main()
{
	char c[100],boy,girl;
	int i,j,len,end=0;

	scanf("%s",c);
	len = strlen(c);
	boy = c[0];
	for(i=1;i<len;i++)
	{
		if(c[i]!=boy)
		{
			girl = c[i];
		}
	}

	while(1)
	{
		for(i=0;i<len;i++)
		{
			if(c[i]==boy)
			{
				for(j=i+1;j<len;j++)
				{
					if(c[j]==' ')continue;
					if(c[j]==girl)
					{
						printf("%d %d\n",i,j);
						c[i] = ' ';
						c[j] = ' ';
						i=0;
						break;
					}
					if(c[j]==boy)break;
				}
			}
		}
		for(i=0;i<len;i++)
		{
			if(c[i]==' ')
			{
				end++;
					if(end==len)
					{
						return 0;
					}
			}
			if(i==len-1&&end<len)
			{
				end = 0;
			}
		}
	}
	return 0;

}


int couple(int);
char a[100];
int len, b[100] = {0};

int main()
{
	cin >> a;
	len = strlen(a);
	couple(0);
	return 0;
}

int couple(int i)
{
	int j;
	for(int k = i; k < len; k++)
	{
		while(b[i] == 1)
		{
			i++;
		}
		if(a[i] == a[0])
		{
			b[i] = 1;
			j = couple(i+1);
			cout << i << " " << j << endl;
		}
		else
		{
			b[i] = 1;
			return i;
		}
	}
}


char queue[100];
char boy,girl;
int stop=0;
int length;
int main()
{

   cin>>queue;
   boy=queue[0];
   length=strlen(queue);
   int number;
   for(int i=0;i<length;i++)
   {
     if(queue[i]!=boy)
		 {
			 girl=queue[i];
			 number=i;
			 break;
	    }
   }
   void handinhand(int);
   handinhand(number);
}

void handinhand(int number)
{
     if(stop==length)
		 return;

	 int theotherside=0;
	 for(int a=1;;a++)
	 {
	     if(queue[number-a]==boy)
			 {
				 theotherside=number-a;
				 break;
		 }

	 }
	 cout<<theotherside<<' '<<number<<endl;
	 queue[number]=' ';
	 queue[theotherside]=' ';
	 stop=stop+2;

	 for(int i=number+1;;i++)
	 {
	         if(queue[i]==girl)
			 {
			      handinhand(i);
			      break;
			 }

	 }

}


/*
 * paiduiyouxi.cpp
 *
 *  Created on: 2011-1-8
 *      Author: lz
 */

int main()
{
	char c[1000];
	int s[1000];
	int top=-1;
	cin>>c;
	char a;
	char b;
	a=c[0];
	int len=strlen(c);
	int i;
	for(i=0;i<len;i++)
		if(c[i]!=a)
		{
			b=c[i];
			break;
		}
	for(i=0;i<len;i++)
	{
		if(c[i]==a)
			s[++top]=i;
		else
			cout<<s[top--]<<" "<<i<<endl;
	}
	return 0;
}


void  change(char a[1001],int i,int j,int k,char boy,char girl)
{

	int l,m,n;
	if(j-i==k-1)
	{
		cout<<"0 "<<k-1;
	    return;
	}
	else
	{
		cout<<i<<" "<<j<<endl;
		a[i]='A';
		a[j]='A';
		for(l=0;l<k;l++)
		{
			if(a[l]==boy)
				{
					for(m=l+1;m<k;m++)
					{
						if(a[m]=='A')
							continue;
					     if(a[m]==boy)
							{
								l=m-1;
								break;
							}

						 if(a[m]==girl)
							return change(a,l,m,k,boy,girl);
					}
				}
		}
	}
}
int main()
{
	char xpy[1001]={0};
	int i,j;
	cin.getline(xpy,1001);
	char boy=xpy[0],girl=xpy[strlen(xpy)-1];
	for(i=0;i<strlen(xpy);i++)
		if(xpy[i]==boy&& xpy[i+1]==girl)
			change(xpy,i,i+1,strlen(xpy),boy,girl);

	return 0;
}


char a[100], p, q;

void solve()
{
	int i=0, b, g;
	while(a[i] != '\0')
	{
		if(a[i] == p)
			b = i;
		else if (a[i] == q)
		{
			g = i;
			a[b] = '0';
			a[g] = '0';
			cout << b << ' ' << g << endl;
			solve();
			break;
		}
		i++;
	}
	return;
}

int main()
{

	cin.get(a,100);
	p = a[0];
	int i=0;
	while(1)
	{
		if(a[i] != p)
		{
			q = a[i];
			break;
		}
		i++;
	}
	solve();

	return 0;
}


int sum ;
void change(int t, char s[],char a, char b)
{
	if (sum == 0)
		return;
	int i, j;
	for (i = 0;i < t;i++)
	{
		if (s[i] == a)
		{
			for (j = i + 1;s[j] == '0' && j < t;j++);
			if (s[j] == b)
			{
				cout << i << " " << j << endl;
				sum = sum - 2;
			    s[i] = s[j] = '0';
				change(t, s,a, b);

			}
		}
	}
}

int main()
{
	char s[105], a, b;
	cin.getline(s, 105);
	int l = strlen(s);
	sum = l;
	a = s[0];
	for (int i = 1;i < l;i++)
	{
		if (s[i] != s[0])
			b = s[i];
	}
	change(l, s, a, b);

	return 0;
}


//????
int main()
{
	char a[102];
	cin.getline(a,102);
	char boy=a[0];
	char girl;
	int length=strlen(a);
   for(int i=1;i<length;i++)
   {
     if(a[i]==boy) continue;
	 else {girl=a[i];break;}
   }
   int t=0;
   int placeofboy[55];
   for(int i=0;i<length;i++)
   {
     if(a[i]==boy) placeofboy[++t]=i;
	 else
	 {
	    cout<<placeofboy[t]<<' '<<i<<endl;
		t--;
	 }
   }

   return 0;
}


void qianshou(int a[], int len)
{
	int i,j, flag = 0;
	for(i = 1; i < len; i++)
	{
		if(a[i] == 2)
		{
			for(j = i - 1; j >= 0 ; j--)
			{
				if(a[j] == 1)
				{
					cout << j << " " << i << endl;
			        a[j] = 0;
					a[i] = 0;
				    break;
				}
			}
		}
	}

}
int main()
{
	char str[100];
	int a[100];
	int i = 0;
	cin.getline(str,100);
	int len;
	len = strlen(str);
	for(i = 0; i < len; i++)
	{
		if(str[0] - '0' == str[i] - '0')
			a[i] = 1;
		else
			a[i] = 2;
	}
	qianshou(a, len);
	return 0;
}


void cool(int n ,char A[100],char a)
{
	int i,j;
	for (i=0;i<n-1;i++)
	{
		if(A[i]!=-1)
		{
		for (j=i+1;j<n;j++)
		{
	        if(A[j]==-1)
				goto loap1;
			if (A[i]==A[j])
				break;
			if (A[i]!=A[j] && A[i]==a)
			{
				printf("%d %d\n",i,j);
				A[i]=-1;
				A[j]=-1;
				goto loap2;
loap1:;
			}
		}
		}
	}
loap2:;
	for (i=0;i<n;i++)
	{
		if (A[i]!=-1)
		{
			cool(n,A,a);
			break;
		}
	}
	return;
}
int main()
{
	char A[100],a;
	int n;
	gets(A);
	n=strlen(A);
	a=A[0];
	cool(n,A,a);
	return 0;
}


int main () {
	char c[1111] ;
	char b , g ;
	int B[1111] , G[1111] ;
	int i , j , k , L , order = 1 ;
	cin >> c ;
	b = c[0] ;
	for ( i = 1 ; ; i ++ ) {
		if ( c[i] != b ) {
			g = c[i] ;
			break ;
		}
	}
	L = strlen(c) ;
	for ( i = 0 ; i < L ; i ++ ) {
		if ( c[i] == b ) {
			for ( j = i+1 ; ; j ++ ) {
				if ( c[j] == ' ' )
					continue ;
				else if ( c[j] == b )
					break ;
				else if ( c[j] == g ) {
					B[order] = i ;
					G[order] = j ;
					c[i] = ' ' ;
					c[j] = ' ' ;
					order ++ ;
					i = -1 ;
					break ;
				}
			}
		}
	}
	for ( i = 1 ; i < order ; i ++ )
		cout << B[i] << " " << G[i] << endl ;
	return 0 ;
}


char a[109];
char boy;
char girl;
int l;
void Match()
{
	if( a[0] != boy )
		return;
	int i = 0;
	while( a[i] != girl )
		i++;
	int j = i-1;
	while( a[j] == '0' )
		j--;
	cout<< j << ' ' << i << endl;
	a[i] = a[j] = '0';
	Match();
}
int main()
{
	cin.getline( a , 109 );
	l = strlen( a );
	boy = a[0];
	girl = a[l-1];
	Match();
	return 0;
}


struct chil
{
	int sex;
	int num;
}child[100];
struct student
{
	int b;
	int g;
}girl[100];
void bubble(struct student a[],int len)
{
	int i, j;
	struct student temp;
	for(j=1; j<len; j++)
	{
		for(i=0; i<len-j; i++)
		{
			if(a[i].g>a[i+1].g)
			{
				temp=a[i];
				a[i]=a[i+1];
				a[i+1]=temp;
			}
		}
	}
}
void main()
{
	int i, j, k, n;
	char s[101];
	gets(s);
	n=strlen(s);
	child[0].sex=1; child[0].num=0;
	for(i=1; i<n; i++)
	{
		if(s[i]==s[0])
		{
			child[i].sex=1; child[i].num=i;
		}
		else
		{
			child[i].sex=0; child[i].num=i;
		}
	}//??????
	for(i=0, j=0; i<n; i++)
	{
		if(child[i].sex==1 && child[i+1].sex==0)
		{
			girl[j].b=child[i].num;
			girl[j].g=child[i+1].num;
			j++;
			for(k=i; (k+2)<n; k++)
				child[k]=child[k+2];
			n=n-2;
			i=-1;
		}
	}
	bubble(girl,j);
	for(i=0; i<j; i++)
		printf("%d %d\n",girl[i].b,girl[i].g);
}


int main()
{
	char bra[100];
	void together(char bra[100]);

	cin.getline(bra,101,'\n');
	together(bra);

	return 0;
}

void together(char bra[100])
{
	int len;
	char ch;							//ch stores the character of boy
	ch=bra[0];
	int k=0,i,j,s;						//s flags the match case of boy and girl
	int bg[50][2];
	len=strlen(bra);
	for (i=1;i<len;i++)					//bra[0] can't be ')'
		if ( bra[i]!=ch )				//for a certain girl,find the boy next to her(loop to left)
		{
			s=1;
			for (j=i-1;j>=0;j--)
			{
				if (bra[j]!=ch)
					s++;
				else
					s--;
				if (s==0)				//if find , s should be 0;
				{
					bg[k][0]=j;			//bg[k][0] is the boy,while bg[k][1] is the girl
					bg[k][1]=i;
					k++;
					break;
				}
			}
		}
	for (i=0;i<k;i++)					//print the result
		cout << bg[i][0] << " " <<bg[i][1] << endl;
}


char line[100],male;
int len;
void hand();
int main()
{
	cin>>line;
	len=strlen(line);
	male=line[0];
	hand();
	return 0;
}
void hand()
{
	int i,j;
	for(i=0;i<len;i++)
	{
		if(line[i]!=male && line[i]!='\0')
		{
			for(j=i-1;j>=0;j--)
			{
				if(line[j]==male)
				{
					cout<<j<<' '<<i<<endl;
					line[i]='\0';
					line[j]='\0';
					break;
				}
			}
		}
	}
}


struct dui
{int nannv;
int weizhi;
}a[100];
void shuchu(struct dui a[100],int n)
{
	int i=1,j,h=1;
	do
	{
		if(a[i].nannv ==0)
		{
			printf("%d %d\n",a[i-1].weizhi-1 ,a[i].weizhi-1 );
			if(i<n)
			{
				for(j=i;j<=n;j++)
				{
					a[j-1]=a[j+1];
					a[j]=a[j+2];
					j++;
				}
				n=n-2;
			}
			else
				n=0;
			i=1;
		}
		else
			i++;
	}while(n!=0);
}
int main()
{
	int i,n,j=0,k=0;
	char s[100],nan;
	scanf("%s",s);
	n=strlen(s);
	nan=s[0];
	for(i=1;i<=n;i++)
	{
		if(s[i-1]==nan)
		{
			a[i].nannv =1;
			a[i].weizhi =i;
		}
		else
		{
			a[i].nannv =0;
			a[i].weizhi =i;
		}
	}
	shuchu(a,n);
}


int main()
{
    int c,std,a=0,i=0,flag=1;
    int boy[100]={0};
    while((c=getchar())!='\n')
    {    if(flag==1)
	{
		std=c;
		flag=0;
	}
	if(c==std)
	{
		boy[i]=a;
		i++;
	}
	else
	{
		printf("%d %d\n",boy[--i],a);
	}
	a++;
    }
	return 0;
}


char	chi[200];
char	boy, gir;
int	pep;

void	zhaoren(int);

int main()
{
	cin.getline(chi, 200);
	pep = strlen(chi);
	boy = chi[0];
	gir = chi[pep - 1];

	zhaoren(pep);

return 0;
}
void	zhaoren(int n)
{
	if(n == 0)
	{return ;}

	for (int i = 0; i < pep; i ++)
	{
		if(chi[i] == gir)
		{
			for (int j = i; j >= 0; j --)
			{
				if(chi[j] == boy)
				{
					cout << j << " " << i << endl;
					chi[j] = '#';
					chi[i] = '#';
					zhaoren(n - 2);
					return;
				}
			}

		}
	}
return;
}


int main()
{
	void row(char x[],int num[],int l,char a,char b);
	char a,b;
	int l,m,n,t,i,q;
	int num[101]={0};
	char x[101];
	gets(x);
	l=strlen(x);
	a=x[0];
	b=x[l-1];
	row(x,num,l,a,b);
	for(m=0;m<l-1;m=m+2)
	{
		for(n=0;n<l-4-m;n=n+2)
		{
			if(num[n+1]>num[n+3])
			{
				t=num[n+1];
				num[n+1]=num[n+3];
				num[n+3]=t;
				q=num[n];
				num[n]=num[n+2];
				num[n+2]=q;
			}
		}
	}
	for(i=0;i<l-1;i=i+2)
	{
		printf("%d %d\n",num[i],num[i+1]);
	}
}

void row(char x[],int num[],int l,char a,char b)
{
	int i,j,t=0,count=0,flag=0;
	for(;count<l/2;)
	{
	for(i=0;i<l;i++)
	{
		if(x[i]!=a)
			continue;
		for(j=i+1,flag=0;j<l;j++)
		{
			if(x[j]==a)
				flag++;
			if(x[j]==b&&flag==0)
			{
				num[t]=i;
				num[t+1]=j;
				x[i]=32;
				x[j]=32;
				count++;
				t=t+2;
				break;
			}
		}
	}
	}
}


int len;
char ren[100];
void search(char ren[100],int k);
int main()
{
	cin >> ren;
	len = strlen(ren);
	search(ren,0);
	return 0;
}
void search(char ren[100],int k)
{
	int i;
	if (k == len - 1)
	{
		cout << 0 << " " << len - 1;
		return;
	}
	if (ren[k] == ren[len - 1])
	{
		for (i = k - 1; i >= 0; i --)
			if (ren[i] == ren[0])
			{
				cout << i << " " << k << endl;
				ren[i] = 0;
				ren[k] = 0;
				break;
			}
			search(ren,k + 1);
	}
	else
		search(ren,k + 1);
}


struct Node;
typedef struct Node *PtrToNode;
typedef PtrToNode Stack;
typedef char ElementType;

int Isempty(Stack S);
Stack CreateStack(void);
void DisposeStack(Stack S);
void MakeEmpty(Stack S);
void Push(ElementType X,int n,Stack S);
int Top(Stack S);
void Pop(Stack S);

/* Place in implementation file */
/* Stack implementation is a linked list with a header */
struct Node
{
	int num;
	ElementType Element;
	PtrToNode Next;
};

int IsEmpty(Stack S)
{
	return S->Next==NULL;
}

Stack CreateStack(void)
{
	Stack S;
	S=malloc(sizeof(struct Node));
	if(S==NULL)
	{
		printf("Out of space!!");
		exit(0);
	}
	S->Next=NULL;
	MakeEmpty(S);
	return S;
}
void MakeEmpty(Stack S)
{
	if(S==NULL)
	{
		printf("Must use CreateStack first");
		exit(0);
	}
	else
		while(!IsEmpty(S))
			Pop(S);
}
void Push(ElementType X,int n,Stack S)
{
	PtrToNode TmpCell;
	TmpCell=malloc(sizeof(struct Node));
	if(TmpCell==NULL)
	{
		printf("Out of space!!");
		exit(0);
	}
	else
	{
		TmpCell->Element=X;
		TmpCell->num=n;
		TmpCell->Next=S->Next;
		S->Next=TmpCell;
	}
}
int Top(Stack S)
{
	if(!IsEmpty(S))
		return S->Next->num;
	printf("Empty stack");
	return 0;
}
void Pop(Stack S)
{
	PtrToNode FirstCell;
	if(IsEmpty(S))
	{
		printf("Empty stack");
		exit(0);
	}
	else
	{
		FirstCell=S->Next;
		S->Next=S->Next->Next;
		free(FirstCell);
	}
}
void main()
{
	Stack S;
	char a[150];
	int i;
	gets(a);
	S=CreateStack();
	for(i=0;a[i]!='\0';i++)
	{
		Push(a[i],i,S);
		while(!IsEmpty(S)&&S->Next->Next!=NULL&&S->Next->Next->Element!=S->Next->Element)
		{
			printf("%d %d\n",Top(S->Next),Top(S));
			Pop(S);
			Pop(S);
		}
	}while(!IsEmpty(S));
	MakeEmpty(S);
}


int main(int argc, char *argv[])
{
  char a[101];
  int b[101]={0};
  scanf("%s",&a);
  int len=strlen(a);
  int i,j;

  int t=1;
  while(t)
  {
    for(i=0;i<len-1;i++)
    {
      if(a[i]==a[0]&&b[i]==0)
      {
      for(j=i+1;j<len;j++)
      {
        if(b[j]==1)
          continue;
        else if(a[j]==a[0])
          break;
        else
        {
          b[i]=1;
          b[j]=1;

          printf("%d %d\n",i,j);
          if(j==len-1)
           t=0;
          i=0;
          break;
        }
      }
      }
    }
  }
   return 0;
}


char a[100];
void match(char a[], char b, char g)
{
    int i, j;
    for (i = 0; ; i++)
    {
        if (a[i] == g)
            break;
    }
    for (j = i; j >= 0; j--)
    {
        if (a[j] == b)
        {
            cout << j << " " << i << endl;
            a[i] = a[j] = '*';
            break;
        }
    }
    if (j == 0)
        return;
    match (a, b, g);
}
int main()
{
    char b, g;
    cin >> a;
    b = a[0];
    for (int i = 1; ; i++)
    {
        if (a[i] != a[0])
        {
            g = a[i];
            break;
        }
    }
    match(a, b, g);
    return 0;
}


int result[100][100]={0};
void match(char str[], int, int, char, char);
int main()
{
   char str[100], boy, girl;
   int len,len1, i, j;
   cin >> str;

   len = strlen(str);
   len1 = len;
   boy = str[0];
   girl = str[len-1];
   match(str, len, len1, boy ,girl);
   for(j=0;j<len;j++)
	   for(i=0;i<len;i++)
	   {
		   if (result[i][j]==1)
			   cout << i << ' ' << j << endl;
	   }
   return 0;
}
void match(char str[],int len, int len1, char boy, char girl)
{
   int i, j;
   if(len1==0) return;
   else
   {
	   for(i=0;i<len;i++)
	   {
		   if(str[i]==boy)
		   {
			  for(j=i+1; ;j++)
			  {
                if(str[j]==boy) break;
				else if(str[j]==girl)
				{
					result[i][j]=1;
					str[i]=' ';
					str[j]=' ';
                    len1 = len1 -2;
					break;
				}
				else continue;
			  }
		   }
	   }
	 match(str,len, len1, boy, girl);
   }
}


int main()
{
	char str[100],boy,girl;
	int len,a[100],i=0,j=0;
	cin.getline(str,100);
	len=strlen(str);
	boy=str[0];
	for(i=0;i<len;i++)
	{
		if(str[i]!=boy)
		{
			girl=str[i];
			break;
		}
	}
	for(i=0;i<len;i++)
	{
		if(str[i]==boy)
			a[i]=1;
		if(str[i]==girl)
			a[i]=-1;
	}
	for(i=0;i<len;i++)
	{
		if(str[i]==girl)
		{
			for(j=i-1;j>=0;j--)
			{
				if(a[j]==1)
				{
					cout<<j<<" "<<i<<endl;
					a[j]=0;
					a[i]=0;
					break;
				}
				if(a[j]==-1)
					break;
			}
		}
	}
	return 0;
}


char queue[1000]={""},boy,girl;
int number,pairs=0;
void findpair(int girlid)
{
	int i;
	if((number/2-pairs)!=1)
	{
		pairs++;
		i=girlid-1;
		while (i>0)
		{if(queue[i]==girl)
		break;
		i--;
		}
		findpair(i);
	}
	for(i=girlid-1;i>=0;i--)
		if(queue[i]==boy)
		{
			printf("%d %d\n",i,girlid);
			queue[i]=0;
			break;
		}
}
int main()
{
	int i;
	gets(queue);
	number=strlen(queue);
	boy=queue[0];
	for(i=0;i<number;i++)
		if(queue[i]!=boy)
		{
			girl=queue[i];
			break;
		}
		findpair(number-1);
		return 0;
}


char boy,girl;
void game(char a[1000])
{
     int i,j,b,g;
     for(i=0;i<1000;i++)
     if(a[i]==girl){for(j=i;j>=0;j--)if(a[j]==boy)break;break;}
     b=j;g=i;
     cout<<b<<' '<<g<<endl;
     a[i]=0;a[j]=0;
     if(a[0]!=0)game(a);
}
int main()
{
    char a[1000]={0};
    int i;
    cin>>a;
    boy=a[0];
    for(i=0;i<1000;i++)if(a[i]!=boy){girl=a[i];break;}
    game(a);
    getchar();getchar();
    return 0;
}


int main()
{
	char str[110]={0};
	int i=0;
	while(true)
	{
		str[i]=getchar();
		if(str[i]=='\n')
			break;
		i++;
	}
	int n,j=0;
	n=i-1;
	for(i=0;i<=n;i++)
	{
		if(str[i]!=str[0])
		{
			str[i]=0;
			for(j=i;j>=0;j--)
			{
				if(str[j]==str[0])
				{
					str[j]=0;
					cout<<j<<" ";
					break;
				}
			}
			cout<<i<<endl;
		}
	}
		return 0;
}


char boy;
void calculate (char children[]);

int main()
{
	char children[101];
	cin >> children;
	boy = children[0];
	calculate(children);

	return 0;
}

void calculate (char children[])
{
	int b, g, i;
	for (i = 0; children[i] != '\0'; i++)
	{
		if (children[i] == boy)
			b = i;
		if (children[i] != boy && children[i] != 1)
		{
			g = i;
			cout << b << " " << g << endl;
			children[b] = children[g] = 1;
			calculate (children);
			break;
		}
	}
}


char dui[150];
char nan;
char nv;
char dis;

int main()
{
    void deleted();
void peidui(int * left , int * right);
int iter,index,left,right;
   gets(dui);
    nan = dui[0];
    index = 1;
    while(dui[index] != '\0')
    {
        if(dui[index] != nan)
        {
            nv = dui[index];
            break;
        }
        index++;
    }
    deleted();
    index = strlen(dui)/2;
    for(iter = 0 ; iter != index ; ++iter)
    {
        peidui(&left,&right);
        printf("%d %d\n",left,right);
    }
    return 0;
}

void deleted()
{
    if('#' != nan && '#' != nv)
    {
        dis = '#';
    }
    else if('@' != nan && '@' != nv)
    {
        dis = '@';
    }
    else if('$' != nan && '$' != nv)
    {
        dis = '$';
    }
}

void peidui(int * left , int * right)
{
    int index = 0;
    int boysready = 0;
    while(dui[index] != '\0')
    {
        if(dui[index] == nan)
        {
            boysready = 1;
            *left = index;
        }
        else if(dui[index] == nv)
        {
            if(boysready)
            {
                *right = index;
                break;
            }
        }
        index++;
    }
    dui[*left] = dui[*right] = dis;
}


char children[101];
char boy;

int f(int i) {
  if (children[i]==boy) {
    int girlPos = f(i+1);
    cout << i << ' ' << girlPos << endl;
    if (i != 0)
      return f(girlPos+1);
    else
      return 0;
  }
  return i;
}

int main() {
  cin >> children;
  boy = children[0];
  f(0);

  return 0;
}


char Boy,Girl;
char queue[100];
int FindPartner(int i)
{
	if(queue[i+1]==Girl)
	{
		cout<<i<<' '<<i+1<<endl;
		return i+1;
	}
	else
	{
		int pnt=i;
		while(queue[pnt+1]==Boy)
		{
			pnt=FindPartner(pnt+1);
		}
		cout<<i<<' '<<pnt+1<<endl;
		return pnt+1;
	}
}
int main()
{
	cin>>queue;
	int l=strlen(queue);
	Boy=queue[0];
	Girl=queue[l-1];
	FindPartner(0);
	return 0;
}


void main()
{
	void f(char s[],int n,int m);
	char s[100];
	int n;
	gets(s);
	n=strlen(s);
	f(s,n,0);
}
void f(char s[],int n,int m)
{
	int i,b,g;
	char *s2;
	if(n==2)
		printf("%d %d\n",m,m+1);
	else
	{
		b=0;
		g=0;
		for(i=0;;i++)
		{
			if(s[i]==s[0])
				b++;
			else
				g++;
			if(b==g)
				break;
		}
		if(i==n-1)
		{
			s2=s+1;
			f(s2,n-2,m+1);
			printf("%d %d\n",m,m+n-1);
		}
		else
		{
			f(s,i+1,m);
			s2=s+i+1;
			f(s2,n-i-1,m+i+1);
		}
	}
}


char child[1000];
char boy, girl;
int search(int);
int main()
{
	int i;
	cin.getline(child,1000);
	boy = child[0];

	for(i = 1; child[i] != '\0'; i++)
	{
		if(child[i] != boy)
		{
			girl = child[i];
			break;
		}
	}
	i = search(0);
	return 0;

}
int search(int m)
{
	int pos;
	if(child[m] != '\0')
	{
	if(child[m]==girl)
		return m;
	else
	{
		pos = search(m + 1);
		cout << m << " " << pos << endl;
		return search(pos + 1);

	}
	}
	else return 0;

}


int main()
{
	char line[100], boy, girl;
	cin >> line;
	int sum;
	sum = strlen(line);
	int i, j, k;
	boy = line[0];
	for (i = 1; i <= sum - 1; i++)  // ?????????
	{
		if (line[i] != boy)
		{
			girl = line[i];
			break;
		}
	}
	for (j = 1; j <= sum - 1; j++)
	{
		if (line[j] != boy)
		{
			for (k = j - 1; k >= 0; k--)
			{
				if (line[k] == boy)
				{
					cout << k << " " << j << endl;
					line[k] = girl;
					break;
				}
			}
		}
	}
	return 0;
}


int match(int);
char a[105], b;

int main()
{
	cin >> a;

	b = a[0];

	match(0);

	return 0;
}

int match(int p)
{
	if (a[p] == b)
	{
		int q = match(p + 1);
		cout << p << " " << q << endl;
		return match(q + 1);
	}
	else
		return p;
}


char boy;

int res(char str[], int n, int idx)
{
	if (str[idx] == boy)
	{
		int ridx = res(str, n, idx + 1);
		cout << idx << " " << ridx << endl;
		if (ridx < n - 1)
		{
			ridx = res(str, n, ridx + 1);
		}
		else
		{
			ridx = ridx + 1;
		}
		return ridx;
	}
	else
	{
		return idx;
	}
}
int main()
{
	char str[102];
	cin >> str;
	boy = str[0];
	res(str, strlen(str), 0);
	return 0;
}


void main()
{
char text[200],a,b; int i,j;
gets(text);printf("\n");
a=text[0];
for(i=0;i<strlen(text);i++)   if(text[i]!=a)  {b=text[i];break;}
for(i=0;i<strlen(text);i++)
{if(text[i]==b)
  {for(j=i;j>=0;j--)   if(text[j]==a)
    {text[j]='c';  printf("%d %d\n",j,i);break;}}}
}


char queen[1000];
// int main()
// {
// 	cin >> queen;
// 	int len = strlen(queen);
// 	char a, b;
// 	int cnt = 0;
// 	int boy[1000] = {0};
// 	a = queen[0];
// 	b = queen[len - 1];
// 	for (int i = 0; i < len; i++)
// 	{
// 		if (queen[i] == a)
// 		{
// 			boy[cnt] = i;
// 			cnt ++;
// 		}
// 		if (queen[i] == b)
// 		{
// 			cnt --;
// 			cout << boy[cnt] << ' ' << i << endl;
// 		}
// 	}
// 	while(EOF!=getchar());
// 	return 0;
// }
	char a, b;
	int cnt = 0;
	int len;
int match(char *);
int main()
{
	cin.getline(queen,1000);
	len = strlen(queen);

	a = queen[0];
	b = queen[len - 1];
	char *p = queen;
	match(p);
	while(EOF!=getchar());
	return 0;
}

int match(char *p)
{
	int q;
	if (*p == b)
	{
		return p - queen;
	}
	else
	{
		q = match(p + 1);
		cout << p - queen << ' ' << q << endl;
		cnt ++;
		if (cnt < len / 2)
		{
					return match(q + queen + 1);
		}

	}

}


char a;
char b;
char s[10000];
int numa=1;
int numb=0;
int ida[10000];
int idb[10000];
void test(int x);
int main()
{
	scanf("%c",&a);
	s[0]=a;
	int i;
	for(i=1;;i++)
	{
		scanf("%c",&s[i]);
		if(s[i]==a)
		{
			numa++;
		}
		else if(s[i]!=a)
		{
			b=s[i];
			numb++;
		}
		if(numa==numb)break;
	}
	test(0);
	for(i=0;i<(numa+numb)/2;i++)
	{
		printf("%d %d\n",ida[i],idb[i]);
	}
	return 0;
}

void test(int x)
{
	int i;
	for(i=0;i<numa+numb;i++)
	{
		if(s[i]==a)
		{
			ida[x]=i;
		}
		else if(s[i]==b)
		{
			idb[x]=i;
			s[ida[x]]=' ';
			s[i]=' ';
			if(x<(numa+numb)/2-1)
			{
				test(x+1);
			}
		}
	}
}


int main()
{
	char ch[101];
	cin.getline(ch,101);
	char b = ch[0];
	char g = ch[0];
	for (int i=0;g==b;i++)
		g = ch[i];
	int length = strlen(ch);
	int gnum = 0;
	for (int i=0;i<(length/2);i++)
	{
		for (gnum++;ch[gnum]==b;gnum++) ;
		int k=1;
		int j;
		for (j=gnum-1;k>0;j--)
		{
			if (ch[j]==b) k--;
			else k++;
		}
		cout<<j+1<<" "<<gnum<<endl;
	}
	return 0;
}


char m, f, flag;

void paidui(char *p, int n)
{
	int i;

	for (i = 1; p[n + i] != '\0'; i++)
	{
		if (p[n + i] == m)
			paidui(p, n + i);
		else
			if(p[n + i] == f)
			{
				p[n] = flag;
				p[n + i] = flag;
				cout << n << " " << (n + i) << endl;
				return;
			}
	}
}

int main()
{

	 char str[100];
	 cin >> str;

	 m = str[0];

	 int i = 0;
	 while(str[i] == m)
		 i++;
	 f = str[i];
     for (i = 'A' ; i <= 'z'; i++)
		 if (i != m && i != f)
		 {
			 flag = i;
			 break;
		 }
	 paidui(str, 0);
	 return 0;
}


char dui[1000];
void rankgame(int left, int right, char male, char female)
{
	if(left == -1)return;
	if(dui[right] == male)
	{
		left = right;
		right++;
		rankgame(left, right, male, female);
	}
	if(dui[left] == 0)
	{
		left --;
		rankgame(left, right, male, female);
	}
	if(dui[left] == male && dui[right] == female)
	{
		cout << left << ' ' << right << endl;
		dui[left] = 0;dui[right] = 0;
		left --;
		right ++;
		rankgame(left, right, male, female);
	}
}
int main()
{
	cin.getline(dui, 1000, '\n');
	char male = dui[0], female = dui[strlen(dui) - 1];
	rankgame(0, 1, male, female);
	return 0;
}


int main()
{
	int n,p,num[255];
	char ch,boy;
	num[0]=0;
	scanf("%c",&boy);
	for(n=p=1;p>0;n++){
		scanf("%c",&ch);
		if(ch==boy){
			num[p]=n;
			p++;
		}
		else{
			printf("%d %d\n",num[p-1],n);
			p--;
		}
	}
	return 0;
}


int len;
char boy,girl;
void paidui(char[]);
int main()
{
	char kids[100];
	cin>>kids;
	len=strlen(kids);
	boy=kids[0];
	girl=kids[len-1];
	paidui(kids);
	return 0;
}
void paidui(char kids[])
{
	int i=0,j;
	while(kids[i]!=girl)
		i++;
	j=i;
	while(kids[j]!=boy)
		j--;
	cout<<j<<" "<<i<<endl;
	kids[i]=kids[j]=1;
	if(kids[len-1]==girl)
		paidui(kids);
}


char a[100], b;
int w;
int find(int);
int main()
{
	cin >> a;
	b = a[0];
	find(0);
	cin.get();
	cin.get();
	return 0;
}

int find(int j)
{
	w = j;
	if(a[j] != b)
		return j;
	else
	{
		cout << j << " " << find(j+1) << endl;
		return find(w+1);
	}
	return 0;
}


int main()
{
	int s[100] = {0}, sum = 0, top = 0;
	char b, a;
	s[0] = 0;
	cin >> b;
	while(top >= 0)
	{
		cin >> a;
		sum++;
		if(a == b)
		{
			s[++top] = sum;
		}
		else
		{
			cout << s[top] << " " << sum<< endl;
			top--;
		}
	}
	return 0;
}


char dui[1000], male, female;
void rankgame(int left, int right)
{
	if(left == -1)return;
	if(dui[right] == male)
	{
		left = right;
		right++;
		rankgame(left, right);
	}
	if(dui[left] == 0)
	{
		left --;
		rankgame(left, right);
	}
	if(dui[left] == male && dui[right] == female)
	{
		cout << left << ' ' << right << endl;
		dui[left] = 0;dui[right] = 0;
		left --;
		right ++;
		rankgame(left, right);
	}
}
int main()
{
	cin.getline(dui, 1000, '\n');
	male = dui[0], female = dui[strlen(dui) - 1];
	rankgame(0, 1);
	return 0;
}


void pipei(char a[]){
	int i,j,p=0;
	char q=a[0];
	int len=strlen(a);
	for(i=p;i<len;i++)
		if(a[i]!=q&&a[i]!='+') {
			p=i;
			break;
		}
	if(i==len) return;
	for(j=i-1;j>=0;j--)
		if(a[j]==q) break;
	cout<<j<<' '<<i<<endl;
	a[j]=a[i]='+';
	pipei(a);
}
int main(){
	char a[100];
	cin>>a;
	pipei(a);
}


int kiss(char ch[], char b, char g, int l, int i){
	int boy;
	int j;
	if(ch[i]!=g) boy=-1;
	else{
		for(j=i-1; j>=0; j--){
			if(ch[j]==b){
				boy=j;
				ch[i]='\0';
				ch[j]='\0';
				break;
			}
			else;
		}
	}
	return(boy);
}

main(){
	char ch[5000], b, g;
	int i, l, girl, boy;
	scanf("%s", ch);
	l=strlen(ch);
	b=ch[0];
	for(i=1; i<l; i++){
		if(ch[i]!=b){
			g=ch[i];
			break;
		}
		else;
	}
	for(i=1; i<l; i++){
		boy=kiss(ch, b, g, l, i);
		if(boy==-1) continue;
		else{
			girl=i;
			printf("%d %d\n", boy, girl);
		}
	}
}


int main()
{
	char str[500],a,b;
	int i,j,len,t,p;
	gets(str);
	len=strlen(str);
	a=str[0];
	b=str[len-1];
	t=2;
	while(t==2){
	for(i=0;i<len-1;i++){
		for(j=i+1;j<len;j++){
			if(str[j]==a)break;
			if(str[j]==b){
				printf("%d %d\n",i,j);
				str[i]='$';
				str[j]='$';
				t=1;
				p=j;
				break;
			}
		}
		if(p==len-1){t=0;break;}
		if(t==1){t=2;break;}
	}
	}
	return 0;
}


char kid[100];
int f(int x)
{
	if (kid[x] == 'g') return x;
	if (kid[x] == 'b') {int g = f(x+1); cout << x << " " << g << endl; return f(g+1);}
}
int main()
{
	int i=0,sum;
	char c,first;
	c=getchar();
	first=c;
	while (c!='\n')
	{
		if (c==first)
		{
			c='b';
		}
		else
		{
			c='g';
		}
		kid[i]=c;
		i+=1;
		c=getchar();
	}//??????????????????i??????
	f(0);
return 0;
}


int main()
{
	char children[101];
	char boy, girl, left;
	cin.getline(children, 101);
	int l = strlen(children), cnt = 0;
	boy = children[0];
	girl = children[l - 1];
	left = boy > girl? (girl - 1) : (boy - 1);
	do
	{
		for(int i = 1; i < l; i++)
		{
			if(children[i] == left)
			{
				i++;
				continue;
			}
			if(children[i] == girl)
			{
				for(int j = i - 1; j >= 0; j--)
				{
					if(children[j] == left)
					{
						j--;
						continue;
					}
					if(children[j] == girl)
						break;
					else
					{
						cout << j << " " << i << endl;
						children[i] = left;
						children[j] = left;
						cnt += 2;
						break;
					}
				}
			}
		}
	}while(cnt != l);
	return 0;
}


char m[100],boy,girl;
int len;
void C();
int findgirl(int);
int main(){
	int i=0;
	cin>>m;
	boy=m[0];
	while(m[i]!='\0'){
		if(m[i]!=boy){
			girl=m[i];
			break;
		}
		else
			i++;
	}
	len=strlen(m);
	for(i=0;i<len/2;i++)
		C();
	return 0;
}
void C(){
	int i,g;
	for(i=0;i<len;i++){
		if(m[i]==boy){
			g=findgirl(i);
			if(g!=0){
				cout<<i<<" "<<g<<endl;
				m[i]='`';m[g]='`';
				break;
			}
		}
	}
}
int findgirl(int i){
	int a;
	if(m[i+1]=='`'){
		a=findgirl(i+1);
		return a;
	}
	else if(m[i+1]==girl)
		return i+1;
	else
		return 0;
}


int main()
{
	char boy, girl;
	char p[100];
	scanf("%s", p);

	boy = p[0];
	int i, j, k = 0;
	for(i = 1; i < strlen(p); i++)
	{
		if(p[i] != boy)
		{
			girl = p[i];
			break;
		}
	}

	struct
	{
		int id;
		char c;
	}
	a[100], t;

	for(i = 0; i < strlen(p); i++)
	{
		a[i].id = i;
		a[i].c = p[i];
	}

	for(i = 0; i < strlen(p) - k; i++)
	{
		if(a[i].c == boy && a[i + 1].c == girl)
		{
			printf("%d %d\n", a[i].id, a[i + 1].id);
			k += 2;
			for(j = i; j < strlen(p) - k; j++)
			{
				a[j] = a[j + 2];
			}
			i = -1;
		}
	}

	return 0;
}


char temp[1000000];
char a,b;

void find (void);

int main (void)
{
	cin.getline(temp,1000000);
	a = temp[0];
	b = temp[strlen(temp)-1];
	find ();

	return 0;
}

void find (void)
{
	int i, index_1, index_2;
	for (i = 0; temp[i] != '\0'; i++)
	{
		if (temp[i] == b)
		{
			index_1 = i;
			temp[i] = ' ';
			break;
		}
	}
	if (temp[i] == '\0')
		return;

	for ( i = index_1; ;i--)
	{
		if (temp[i]==a )
		{
			index_2 = i;
			temp [i] = ' ';
			break;
		}
	}
	cout << index_2<<' '<<index_1 << endl;
	find();
	return;
}


struct children
{
	char bracket;
	int code;
};
char boy,girl;

void main()
{
	void func(struct children chd[],int n);
	int scan(struct children *p,char string[100]);
	struct children chd[100]={'\0',0};
	struct children *p;
	p=chd;
	char str[100];
	scanf("%s",str);
	int len=scan(p,str);
    boy=str[0];
    int point=0;
	for(point=0;point<len;point++)
	{
		if(str[point]!=boy)
		{
			girl=str[point];
			break;
		}
	}
	func(chd,len);
}

void func(struct children chd[],int n)
{
	void exile(struct children chd[],int friendcode,int lenx);
	int j=0;
	for(j=0;j<n;j++)
	{
		if(chd[j].bracket=='\0') break;
	    if(chd[j].bracket==boy && chd[j+1].bracket==girl)
		{
			printf("%d %d\n",chd[j].code,chd[j+1].code);
			exile(chd,j,n);
		    j=j-1;
			n=n-2;
		}
		else
		{
			if(chd[j].bracket==boy &&chd[j+1].bracket==boy) func(chd+1,n-1);
			else
			{
			    if(chd[j].bracket==girl)
				{
				    func(chd-1,n+1);
				}
			}
		}
	}
}

int scan(struct children *p,char string[100])
{
	int i=0;
	while(string[i]!='\0')
	{
        p->bracket=string[i];
		p->code=i;
		p+=1;
		i+=1;
	}
	return(i);
}
void exile(struct children chd[],int friendcode,int lenx)
{
	int k=0;
	for(k=friendcode;k<lenx-1;k++)
	{
		chd[k]=chd[k+2];
	}
}


int i;
int num;
char s[102];
	char c1 ;
	char c2;
int sol()
{
	if(i >= num)
		return -1;
	int n = i;
	char b = s[i++];
	if(b == c1)
	{
		cout<<n<<" "<<sol()<<endl;
		return sol();
	}
	else if(b == c2)
		return n;
}
int main()
{

	cin>>s;
	num = strlen(s);
	c1 = s[0];
	for(int i = 1;i<num;i++)
	{
		if(s[i] != c1)
		{
			c2 = s[i];
			break;
		}
	}
	sol();
}


int main()
{
	char boy,girl,children[102]={'\0'};
	int sum,i,j;//sum???????????
	cin.getline(children,101,'\n');
	sum=strlen(children);
	boy=children[0];
	girl=children[sum-1];
	while(children[sum-1]!='\0')
	{
		j=0;
		while(children[j]!=girl&&j<sum)//???????????
			j++;
		i=j-1;
		while(children[i]!=boy&&i>=0)//?????????????????
			i--;
		children[i]='\0';//??????
		children[j]='\0';
		if(j==sum-1)//????????
			cout<<i<<" "<<j;
		else
			cout<<i<<" "<<j<<endl;
	}
	return 0;
}


int main ()
{
	char s[100];
	char boy, girl, null;
	int i, j, l;
	null = '0';
	scanf ("%s", s);
	l = strlen (s);
	boy = s[0];
	for (i = 0; i < l; i++)
	{
		if (s[i] != s[0])
		{
			girl = s[i];
			break;
		}
	}
	for (i = 0; i < l; i++)
	{
		if (s[i] != null)
		{
		    if (s[i] == girl)
			{
			    for (j = i - 1; j >= 0; j--)
				{
					if (s[j] == boy)
					{
						printf("%d %d\n", j, i);
						s[i] = null;
						s[j] = null;
						break;
					}
				}
			}
		}
	}
	return 0;
}


int counter=0;
void match()
{
    char temp;
    temp=cin.get();
    int num1=counter++;
    while(cin.peek()==temp)
        match();
    cin.get();
    cout<<num1<<' '<<counter++<<endl;
}

int main()
{
    match();
    return 0;
}


char a[100], b, g;
int x[100], y[100];
int l;

void couple(int n)
{
	if(n == 0)
		return;
	else
	{
		for(int i = 0; i < l-1; i++)
		{
			int j = i + 1;
			if(a[i] == b)
			{
				while(a[j] == '0')
					j++;
				if(a[j] == g)
				{
					cout << i << " " << j << endl;
					a[i] = a[j] = '0';
					return couple(n-2);
				}
			}
		}

	}
}

int main()
{
	cin >> a;
	l = strlen(a);
	b = a[0];
	for(int i = 1; i < l; i++)
	{
		if(a[i] != b)
		{
			g = a[i];
			break;
		}
	}
	couple(l);
	return 0;
}


void f(char a[1000], char b, char g, int len, int k)
{
	int i, j;

    while(k < len - 1)
	{
	for(i = k;i < len;i++)
	{
		if(a[i] == g)     break;
	}

	for(j = i-1;j > 0;j--)
	{
		if(a[j] == b)     break;
	}
	if(i == len) break;
	cout << j << " " <<i << endl;
	a[i] = ' ';
	a[j] = ' ';
	f(a, b, g, len, i+1);
	}

}
int main ()
{
	char a[1000], b, g;
	int len, k = 0;
	cin.getline(a, 1000);
	len = strlen(a);
	b = a[0];
	g = a[len - 1];
    f(a, b, g, len, k);
	return 0;
}


int main(){
char kid[101];
scanf("%s",kid);
int zuhe[51][2];
char sigb;
int i,j=0,p;
sigb=kid[0];
for(i=0;i<strlen(kid);i++){
    if(kid[i]!=sigb){
        zuhe[j][1]=i;
        j++;
    }
}
for(j=0;j<strlen(kid)/2;j++){
    p=zuhe[j][1]-1;
    while(kid[p]!=sigb){
            p--;
    }
    zuhe[j][0]=p;
    kid[p]='0';
}
for(j=0;j<strlen(kid)/2;j++){
    printf("%d %d\n",zuhe[j][0],zuhe[j][1]);
}
return 0;
}


int main()
{
	char s[100],a,b;
	int slen,i,j;
	scanf("%s",s);
	slen=strlen(s);
	a=s[0];
	for(i=0;i<slen;i++)
	{
		if(s[i]!=s[0])
		{
			b=s[i];
			break;
		}
	}
	for(i=0;i<slen;i++)
	{
		if(s[i]==b)
		{
			for(j=i-1;j>=0;j--)
			{
				if(s[j]==a)
				{
					printf("%d %d\n",j,i);
					s[j]=0;
					break;
				}
			}
		}
	}
	return 0;
}


char str[100];

int match(char str[], char b, char g)
{
	int i, j;
	for(i = 0; str[i] != '\0'; i++)
	{
		if(str[i] == g)
			break;
	}
	if(str[i] == '\0')
		return 0;
	for(j = i; j >= 0; j--)
	{
		if(str[j] == b)
		{
			cout << j << " " << i << endl;
			break;
		}
	}
	str[i] = '#';
	str[j] = '#';
	match(str, b, g);
}

int main()
{
	char b, g;
	cin >> str;
	b = str[0];
	int i, length;
	length = strlen(str);
	for(i = 0; i < length; i++)
	{
		if(str[i] != b)
		{
			g = str[i];
			break;
		}
	}
	match(str, b, g);
	return 0;
}


/**
* @file 1.cpp
* @author ???
* @date 2011-09-24
* @description
* ??????:?????
*/

// ??????pai???
int pai(char xiao[], int n, int v, int i)
{
	int j, k;
	if (xiao[i + 1] == 0)
		return 0;
	for (j = i + 1; xiao[j] != 0; j++)
	{
		if (xiao[j] == v)
			break;
	}
	for (k = j; xiao[k] != 0; k--)
	{
		if (xiao[k] == n)
		{
			xiao[k] = 1;
			break;
		}
	}
	cout << k << ' ' << j <<endl;
	pai(xiao, n, v, j);
	return 0;
}

int main()
{
	int n, i, v;
	char xiao[100] = {0};
	cin >> xiao;
	n = xiao[0];
	for (i = 1; i <= 100; i++)
	{
		if(xiao[i] != n)
		{
			v = xiao[i];
			break;
		}
	}
	pai(xiao, n, v, i - 1);
	return 0;
}


int main()
{
	void handinhand(char xpy[],int num ,int left,char boy,char girl);
	char xpy[101]={'\0'},boy,girl;
	int num;
	cin.getline(xpy,100);//?????
	boy=xpy[0];//????
	for (num=0;xpy[num]!=0;num++) ;
	girl=xpy[num-1];//????
	handinhand(xpy,num,num,boy,girl);//????????
	return 0;
}
void handinhand(char xpy[],int num,int left,char boy,char girl)
{
	int i=0,j,lf=left;
	if (left>0)//??????0
	{
		for (i=0;xpy[i]!=girl;i++) ;//???????,?????????
		for (j=i-1;xpy[j]!=boy&&j>-1;j--) ;//????????????????????
		cout<<j<<' '<<i<<endl;//??2???
		lf=left-2;//??????
		xpy[i]=0;//??2???
		xpy[j]=0;//
		handinhand(xpy,num,lf,boy,girl);//?????????
	}
}


/*
 * yi.cpp
 *
 *  Created on: 2012-10-20
 *      Author: 7
 */
int main()
{
	char s[500];
	int left[500],num[500];
	int flag=0,temp;
	cin>>s;
	int l,i=0,k=0,j;
	for(i=0;i<500;i++)
		num[i]=1000;
	l=strlen(s);
	for(i=0;i<l;i++)
	{
		if(s[i]==s[0])
		{
			left[k]=i;
			k++;
		}
		else
		{
			k--;
			num[flag]=left[k];
			num[flag+1]=i;
			flag=flag+2;
		}
	}
	for(i=0;i<flag;i=i+2)
	{
		for(j=0;j<flag-i;j=j+2)
		{
			if(num[j+1]>num[j+3])
			{
				temp=num[j];
				num[j]=num[j+2];
				num[j+2]=temp;
				temp=num[j+1];
				num[j+1]=num[j+3];
				num[j+3]=temp;
			}
		}
	}
		for(i=0;i<flag;i=i+2)
		{
			cout<<num[i]<<' '<<num[i+1]<<endl;
		}

}


int flag[101]={0};
char str[101];
char b,g;
void match(int girl)              //int girl's pos
{
	int j;
	for(j=girl;j>=0;j--)
	{
		if(str[j]==b&&flag[j]==0)
		{
			cout<<j<<' '<<girl<<endl;
			flag[j]=1;
			break;
		}
	}
	return ;
}

int main()
{
	int i=0;
	cin >> str;
	b=str[0];
	int len=strlen(str);
	while(str[i]==b)i++;
	g=str[i];
	for(;i<=len-1;i++)
	{
		if(str[i]==g)match(i);
	}
	return 0;
}


struct ranking
{
            int sex;
            int order;
}stu[100];
void check(int len)
{
     int x,y;
     for(x=0; x< len-1; x++){
              if(stu[x].sex ==1 && stu[x+1].sex ==0){
                            cout << stu[x].order <<" " << stu[x+1].order << endl;
                            for(y=x; y<len-2; y++){
                                     stu[y]= stu[y+2];
                            }
                            return;
              }
     }
}

int main(int argc, char *argv[])
{
    char ary[100], boy, girl;
    int len, order[100];
    int i,j,k;
    gets(ary);
    len = strlen(ary);
    if(len%2 ==0){
             for(i=0; i<len; i++){
                      order[i]= ary[i] == ary[0]? 1:0;
             }

             for(j=0; j< len; j++){
                      stu[j].sex= order[j];
                      stu[j].order= j;
             }
             while(len!=0){
                           check(len);
                           len-=2;
             }
    }
    else
    cout<< "wrong input" << endl;

    return EXIT_SUCCESS;
}


char dui_lie[100],zuo,you;
int zuobian,youbian,changdu;//??????

void qian_shou(int zuobian)//????
{
    for(youbian=zuobian+1;youbian<changdu;youbian++)
    {
                              if(dui_lie[youbian]==zuo || dui_lie[youbian]==you)
                              break;
    }//???????????????????????
    if(dui_lie[youbian]==you)
    {
                             dui_lie[zuobian]='*';
                             dui_lie[youbian]='*';
                             cout<<zuobian<<" "<<youbian<<endl;
    }//????????????????????????
    else
    {
        zuobian=youbian;
        qian_shou(zuobian);
    }//?????????????????????????????
}

int main()
{

    int i;
    cin>>dui_lie;
    changdu=strlen(dui_lie);
    zuo=dui_lie[0];
    you=dui_lie[changdu-1];//????????????
    for(i=1;i<=changdu/2;i++)
    {
                        zuobian=0;//???????????????
                        qian_shou(zuobian);
    } //???????????
return 0;
}


int judge(int s,char k[])
{
	int sum=0,p;
	for(int i=0;i<s;i++){
		if (k[i]==' '){
			sum++;}}
	if (sum==s)p=1;
	else p=0;
	return(p);
}
int main()
{
	int i=0;
	char kids[110],boy,gal;
	cin.getline(kids,110);
	for(i=0;i<strlen(kids);i++)
	    if (kids[i]!=kids[i+1]){
			boy=kids[i];
			gal=kids[i+1];
			break;}
	while(judge(strlen(kids),kids)!=1){
		if (kids[i]==boy&&kids[i+1]==gal){
			cout<<i<<" "<<i+1<<endl;
			kids[i]=' ';
			kids[i+1]=' ';
			i=0;}
		else if (kids[i]==' '&&kids[i+1]==gal){
			for(int j=i;j>=0;j--){
				if (kids[j]==boy){
					cout<<j<<" "<<i+1<<endl;
					kids[i+1]=' ';
					kids[j]=' ';
					i=0;
					break;}}}
		else i++;}
	return 0;
}


int flag[100]={0};
void pailie(char b[100],int l)
{
	int i,j;
	int g=0;
	if(flag[l-1]==1);
        else
	{
	   for(i=0,g=0;i<l;i++)
	   {
		if(flag[i]==1) continue;
		for(j=i+1;j<l;j++)
		{
			if(flag[j]==1) continue;
			if(b[i]!=b[j])
			{
				cout<<i<<' '<<j<<endl;
				flag[j]=1;
				g=1;
				flag[i]=1;
				break;
			}
			else break;
	   	}
		if(g==1) break;
	    }
	pailie(b,l);
	}
}
int main ()
{
	char a[100];
	int i,len;
	cin.getline(a,100);
	len = strlen(a);
	pailie(a,len);
	return 0;
}


char line[1000];
int search(int a)
{
    int i, j, flag=0;
    for (i=a-1;i>=0;i--)
    {
        if ((line[i]+line[a]==line[strlen(line)-1]+line[0])&&(flag==0))
        {
            for (j=a-1;j>=0;j--)
            {
                if (line[j]==line[strlen(line)-1])
                {
                    search (j);
                    break;
                }
            }
            if (j==0)
            return 0;
            cout << i << " " << a << endl;
            break;
        }
        if (line[i]+line[a]!=line[strlen(line)-1]+line[0])
        flag++;
        if ((line[i]+line[a]==line[strlen(line)-1]+line[0])&&(flag!=0))
        flag--;
    }
}
int main()
{
    memset(line, 0, sizeof(line));
    cin >> line;
    search (strlen(line)-1);
    return 0;
}


char str[100];
char x,y;
void line(char a[])
{
	int i,j;
	for(i=0;i<strlen(a);i++)
	{
		if(a[i]==y)
		{
			j=i;
			while (a[j]!=x)
			{
				j--;
			}
			a[i]='0';
			a[j]='0';
			cout << j << " " << i << endl;
			break;
		}
	}
	if(i<strlen(a))
	{
		line(a);
	}
}
int main()
{
	cin >> str;
	x=str[0];
	y=str[strlen(str)-1];
	line(str);
	return 0;
}


char a[1000];

int xx (int k)
{
     int x,y;
     x=k;
     y=k+1;
     while (a[y]==a[x])
     y=xx(y);
     cout <<x<<" "<<y<<endl;
     return y+1;
}

int main ()
{
    cin.getline(a,999,'\n');
    xx(0);
    return 0;
}


void main()
{
	void pr(char *a,int n,char boy,char girl,int *k);
	char boy,girl,a[100];
	int i,b=0,g=0,k[100];
	for(i=0;;i++)
	{
		scanf("%c",&a[i]);
		if(a[i]==a[0])b++;
		else g++;
		if(b==g)break;
	}
	boy=a[0];girl=a[b*2-1];
	for(i=0;i<100;i++)k[i]=i;
	pr(a,2*b,boy,girl,k);
}

void pr(char *a,int n,char boy,char girl,int *k)
{
	int i;
	for(i=0;i<n;i++)
	{
		if(*(a+i)==girl)
		{
			printf("%d %d\n",*(k+i-1),*(k+i));
			i--;
			break;
		}
	}
	for(;i<n-2;i++)
	{
		*(a+i)=*(a+i+2);
		*(k+i)=*(k+i+2);
	}
	if(n>3)pr(a,n-2,boy,girl,k);
}


char row[100];
void pipei( int i, char boy, char girl )
{
	int j;
	if ( row[i] == girl )
	{
		for ( j = i - 1; j >= 0; j-- )
		{
			if ( row[j] == boy )
			{
				cout << j << " " << i << endl;
				row[j] = ' ';
				row[i] = ' ';
				break;

		    }
	    }
	}
	if ( row[i + 1] != '\0' )
		pipei( i + 1, boy, girl);

}

int main()
{
	char girl, boy;
	cin.getline( row, 100 );
	boy = row[0];
	int i;
	for ( i = 0; row[i] != '\0'; i++ )
	{
		if ( row[i] != boy )
		{
			girl = row[i];
			break;
		}
	}
	pipei( 1, boy, girl );
	return 0;
}


int main(){
	char boy,girl,s[520];
	int n,i,m,total,j;
	struct f{
		char c;
		int judge;
	}child[520];
	scanf("%s",s);
	boy=s[0];
	for (i=1;s[i]!='\0';i++){
		if (s[i]!=boy){
			girl=s[i];
			break;
		}
	}
	for (i=0;s[i]!='\0';i++){
		child[i].c=s[i];
		child[i].judge=1;
	}
	m=i;
	total=i;
	for (n=1;m!=0;n++){
		for (i=0;i<total-2;i++){
			if (child[i].c==boy&&child[i].judge==1){
				for (j=i+1;j<=total-1;j++){
					if (child[j].judge==1&&child[j].c==boy)
						j=m+100;
					else if (child[j].judge==1&&child[j].c==girl){
						printf("%d %d\n",i,j);
						child[i].judge=0;
						child[j].judge=0;
						j=m+100;
						i=total+100;
						m=m-2;
					}
				}
			}
		}
	}
	return 0;
}


int main()
{int cur=0,stack[100],sum=0;
 char x,sign;
 sign=cin.peek();
 do
 {
  cin>>x;
  if(x==sign)
   stack[cur++]=sum++;
  else
   cout<<stack[--cur]<<' '<<sum++<<endl;
 }while(cur>0);
 return 0;
}


int sum(int line2[],int a,int b)
{
	int i,c=0;
	for(i=a;i<=b;i++)
		c+=line2[i];
	return(c);
}

int main()
{
	char line[100];
	int line1[100],i,j,k,line3[50][2]={0};
	scanf("%s",line);
	k=strlen(line)/2-1;
	for(i=0;i<strlen(line);i++)
	{
		if(line[i]==line[0])
			line1[i]=1;
		if(line[i]==line[strlen(line)-1])
			line1[i]=-1;
	}
	for(i=strlen(line)-1;i>=0;i--)
	{
		if(line1[i]==-1)
			for(j=i-1;j>=0;j--)
				if(sum(line1,j,i)==0)
				{
					line3[k][0]=j;
					line3[k][1]=i;
					k--;
					break;
				}
	}
	for(i=0;i<strlen(line)/2;i++)
		printf("%d %d\n",line3[i][0],line3[i][1]);
	return 0;
}


int x = 0;
int a[50];
char str[100];
char b, g;
int l;
int main()
{
	cin.getline(str, 100, '\n');
	l = strlen(str);
	b = str[0];
	g = str[l - 1];
	game(0, 0, 1);
	return 0;
}
void game(int k, int i, int j)
{
	if (j == l - 1)
	{
		cout << "0 " << l - 1;
	}
	else
	{
		if (str[j] == g)
		{
			cout << i << " " << j << endl;
			x = x - 1;
			game(a[x], i - k, j + 1);
		}
		else
		{
			a[x] = k;
			x = x + 1;
			game(j - i, j, j + 1);
		}
	}
}


/*
 * chengtizhong.cpp
 *
 *  Created on: 2012-1-10
 *      Author: Administrator
 */
int main()
{
	int z,q,s,l;
	int number[4];
	char name[4]={'z','q','s','l'};
	for(z=1;z<=5;z++)
	{
		for(q=1;q<=5;q++)
		{
			for(s=1;s<=5;s++)
			{
				for(l=1;l<=5;l++)
				{
					if((z+q)==(s+l))
					{
						if((z+l)>(s+q))
						{
							if((z+s)<q)
							{
								number[0]=z;
								number[1]=q;
								number[2]=s;
								number[3]=l;
							}
						}
					}
				}
			}
		}
	}
	int i,j,temp;
	char temp1;
	for(i=0;i<4;i++)
	{
		for(j=0;j<3-i;j++)
		{
			if(number[j]<number[j+1])
			{
				temp=number[j+1];temp1=name[j+1];
				number[j+1]=number[j];name[j+1]=name[j];
				number[j]=temp;name[j]=temp1;
			}
		}
	}
	for(i=0;i<4;i++)
	{
		cout<<name[i]<<" "<<number[i]*10<<endl;
	}
	return 0;
}


int main(void)
{
	int zhao, qian, sun, li;
	for(zhao = 1; zhao <= 5; zhao++)
		for(qian = 0; qian <= 5; qian++)
			for(sun = 1; sun <= 5; sun++)
			{
				li = zhao + qian - sun;
				if(li <= 5 && li > 0)
				if((zhao + li > sun + qian) && (zhao + sun < qian))
				if(zhao != qian && zhao != sun && zhao != li)
				if(qian != sun && qian != li)
				if(sun != li)
				for(int i = 5; i >= 1; i--)
				{
					if(zhao == i) cout << "z " << zhao * 10 << endl;
					if(qian == i) cout << "q " << qian * 10<< endl;
					if(sun == i) cout << "s " << sun * 10<< endl;
					if(li == i) cout << "l " << li * 10<< endl;
				}
			}
	return 0;
}


int main()
{
	int q,z,s,l,s1,s2,s3;
	char weight[6];
	memset(weight,0,sizeof(weight));
	for(q=1;q<6;q++)
		for(z=1;z<6;z++)
		{
			if(z==q)continue;
			for(s=1;s<6;s++)
			{
				if(s==z||s==q)continue;
				for(l=1;l<6;l++)
				{
					if(l==s||l==z||l==q)continue;
					s1=(z+q)==(s+l);
					s2=(z+l)>(s+q);
					s3=(z+s)<q;
					if(s1+s2+s3==3)
					{
						weight[q]='q';
						weight[z]='z';
						weight[s]='s';
						weight[l]='l';
						for(int i=5;i>0;i--)
							if(weight[i]!='\0')
								cout<<weight[i]<<' '<<i*10<<endl;
					}
				}
			}
		}
	return 0;
}


int main()
{
	int z,q,s,l;
	int zWeight,qWeight,sWeight,lWeight;
	for(z=1;z<=5;z++)
	{
		for(q=1;q<=5;q++)
		{
			for(s=1;s<=5;s++)
			{
				for(l=1;l<=5;l++)
				{
					if(z+q==s+l&&z+l>s+q&&z+s<q)
					{
						zWeight=10*z;
						qWeight=10*q;
						sWeight=10*s;
						lWeight=10*l;
					}
				}
			}
		}
	}
	if(lWeight>qWeight&&qWeight>zWeight&&zWeight>sWeight)
			{
			cout<<"l"<<" "<<lWeight<<endl;
			cout<<"q"<<" "<<qWeight<<endl;
			cout<<"z"<<" "<<zWeight<<endl;
			cout<<"s"<<" "<<sWeight<<endl;
			}
	if(lWeight>qWeight&&qWeight>sWeight&&sWeight>zWeight)
			{
			cout<<"l"<<" "<<lWeight<<endl;
			cout<<"q"<<" "<<qWeight<<endl;
			cout<<"s"<<" "<<sWeight<<endl;
			cout<<"z"<<" "<<zWeight<<endl;
			}

}


int main()
{
	int weight[4],i,j,k;
	char name[4][2]={"z","q","s","l"},t[2];
	for (weight[0]=1;weight[0]<5;weight[0]++)
	{
		for (weight[1]=1;weight[1]<5;weight[1]++)
		{
			for (weight[2]=1;weight[2]<5;weight[2]++)
			{
				for (weight[3]=1;weight[3]<5;weight[3]++)
				{
					if (weight[0]+weight[1]==weight[2]+weight[3] && weight[0]+weight[3]>weight[2]+weight[1] && weight[0]+weight[2]<weight[1])
						break;
				}
				if (weight[0]+weight[1]==weight[2]+weight[3] && weight[0]+weight[3]>weight[2]+weight[1] && weight[0]+weight[2]<weight[1])
						break;
			}
			if (weight[0]+weight[1]==weight[2]+weight[3] && weight[0]+weight[3]>weight[2]+weight[1] && weight[0]+weight[2]<weight[1])
						break;
		}
		if (weight[0]+weight[1]==weight[2]+weight[3] && weight[0]+weight[3]>weight[2]+weight[1] && weight[0]+weight[2]<weight[1])
						break;
	}
	for (i=0;i<4;i++)
	{
		for(j=1;j<4-i;j++)
		{
			if(weight[j-1]<weight[j])
			{
				k=weight[j-1];weight[j-1]=weight[j];weight[j]=k;
				strcpy(t,name[j-1]);
				strcpy(name[j-1],name[j]);
				strcpy(name[j],t);
			}
		}
	}
	for (i=0;i<4;i++)
		cout <<name[i]<<" "<<10*weight[i]<<endl;
	return 0;

}


int main()
{
    /*printf("l 50\n");
    printf("q 40\n");
    printf("z 20\n");
    printf("s 10");*/
    int z,q,s,l;
    for(z=1;z<=5;z++){
    for(q=1;q<=5;q++){
    for(s=1;s<=5;s++){
    for(l=1;l<=5;l++){
    if(z+q!=s+l)
    continue;
    else if(z+l<=s+q)
    continue;
    else if(z+s>=q)
    continue;
    if(z==q || z==s || z==l || q==s || q==l || s==l)
    continue;
    else
    goto l;
    }
    }
    }
    }
l:  z*=10; q*=10; s*=10; l*=10;
    char bskc,name[4]={'z','q','s','l'};
    int bski,weight[4];
    weight[0]=z; weight[1]=q; weight[2]=s; weight[3]=l;
    for(int i=0;i<4;i++){
    for(int j=i+1;j<4;j++){
    if(weight[i]<weight[j])
    {
        bski=weight[i];
        weight[i]=weight[j];
        weight[j]=bski;
        bskc=name[i];
        name[i]=name[j];
        name[j]=bskc;
    }
    }
    }
    for(int i=0;i<4;i++)
    printf("%c %d\n",name[i],weight[i]);
    return 0;
}


int main()
{
  int a,b,c,d;
  a=50;
  b=40;
  c=20;
  d=10;
  printf("l %d\n",a);
  printf("q %d\n",b);
  printf("z %d\n",c);
  printf("s %d\n",d);
  return 0;
}


int main()
{
    int a,b,c,d;
    a=20;
    b=40;
    c=10;
    d=50;
    printf("l %d\nq %d\nz %d\ns %d",d,b,a,c);

    return 0;
}


struct person{
	char name;
	int weight;
}p[4];

//p0=z p1=q p2=s p3=l

int check(int a,int b,int c,int d){
	if(a!=b&&a!=c&&a!=d&&b!=c&&b!=d&&c!=d){
		return 1;
	}else{
		return 0;
	}
}

void main(){
	int i,j,tempw;
	char tempc;
	p[0].name='z';
	p[1].name='q';
	p[2].name='s';
	p[3].name='l';
	for(p[0].weight=10;p[0].weight<=50;p[0].weight=p[0].weight+10){
		for(p[1].weight=10;p[1].weight<=50;p[1].weight=p[1].weight+10){
			for(p[2].weight=10;p[2].weight<=50;p[2].weight=p[2].weight+10){
				for(p[3].weight=10;p[3].weight<=50;p[3].weight=p[3].weight+10){
					if(check(p[0].weight,p[1].weight,p[2].weight,p[3].weight)){
						if((p[0].weight+p[1].weight==p[2].weight+p[3].weight)&&(p[0].weight+p[3].weight>p[1].weight+p[2].weight)&&(p[0].weight+p[2].weight<p[1].weight)){
							for(i=3;i>0;i--){
								for(j=0;j<i;j++){
									if(p[j].weight<p[j+1].weight){
										tempw=p[j].weight;
										p[j].weight=p[j+1].weight;
										p[j+1].weight=tempw;
										tempc=p[j].name;
										p[j].name=p[j+1].name;
										p[j+1].name=tempc;
									}
								}
							}
							for(i=0;i<4;i++){
								printf("%c %d\n",p[i].name,p[i].weight);
							}
						}
					}
				}
			}
		}
	}
}


int main()
{
 int z , q , s , l , min , smin , smax , max;
 for(z=1;z<=5;z++)
 {
  for(q=1;q<=5;q++)
  {
   for(s=1;s<=5;s++)
   {
    for(l=1;l<=5;l++)
    {
     if((z!=q)&&(z!=s)&&(z!=l)&&(q!=s)&&(q!=l)&&(s!=l))
      {
       if(z+q==s+l)
       {
         if(z+l>s+q)
         {
          if (z+s<q)
           {
            min = z ;
            if (q<min)
            {
             min =q;
            }
            if (s<min)
            {
             min=s;
            }
            if (l<min)
            {
             min=l;
            }
            max = z;
            if (q>max)
            {
             max =q;
            }
            if (s>max)
            {
             max=s;
            }
            if (l>max)
            {
             max=l;
            }
           if((z-min)*(z-max)*(q-min)*(q-max)!=0)
           {
            if (z>q)
            {
            smax=z;
            smin=q;
            }
            else
            {
             smin=z;
             smax=q;
             }
            }
           if((z-min)*(z-max)*(s-min)*(s-max)!=0)
           {
            if (z>s)
            {
            smax=z;
            smin=s;
            }
            else
            {
             smin=z;
             smax=s;
             }
            }
           if((z-min)*(z-max)*(l-min)*(l-max)!=0)
           {
            if (z>l)
            {
            smax=z;
            smin=l;
            }
            else
            {
             smin=z;
             smax=l;
             }
            }
		   if((q-min)*(q-max)*(s-min)*(s-max)!=0)
           {
            if (s>q)
            {
            smax=s;
            smin=q;
            }
            else
            {
             smin=s;
             smax=q;
             }
            }
          if((l-min)*(l-max)*(q-min)*(q-max)!=0)
           {
            if (l>q)
            {
            smax=l;
            smin=q;
            }
            else
            {
             smin=l;
             smax=q;
             }
            }
           if((s-min)*(s-max)*(l-min)*(l-max)!=0)
           {
            if (s>l)
            {
            smax=s;
            smin=l;
            }
            else
            {
             smin=l;
             smax=l;
             }
            }
          if(z==max)
           {
            cout<<"z"<<" "<<z*10<<endl;
           }
           if(q==max)
           {
            cout<<"q"<<" "<<q*10<<endl;
           }
           if(s==max)
           {
            cout<<"s"<<" "<<s*10<<endl;
           }
           if(l==max)
           {
            cout<<"l"<<" "<<l*10<<endl;
           }
           if(z==smax)
           {
            cout<<"z"<<" "<<z*10<<endl;
           }
           if(q==smax)
           {
            cout<<"q"<<" "<<q*10<<endl;
           }
           if(s==smax)
           {
            cout<<"s"<<" "<<s*10<<endl;
           }
           if(l==smax)
           {
            cout<<"l"<<" "<<l*10<<endl;
           }
           if(z==smin)
           {
            cout<<"z"<<" "<<z*10<<endl;
           }
           if(q==smin)
           {
            cout<<"q"<<" "<<q*10<<endl;
           }
           if(s==smin)
           {
            cout<<"s"<<" "<<s*10<<endl;
           }
           if(l==smin)
           {
            cout<<"l"<<" "<<l*10<<endl;
           }
           if(z==min)
           {
            cout<<"z"<<" "<<z*10<<endl;
           }
           if(q==min)
           {
            cout<<"q"<<" "<<q*10<<endl;
           }
           if(s==min)
           {
            cout<<"s"<<" "<<s*10<<endl;
           }
           if(l==min)
           {
            cout<<"l"<<" "<<l*10<<endl;
           }
}
}
}
}
}
}
}
}
return 0;
}


int main( )
{ void sort(int,int,int,int);
  int a,b,c,d;
  for (a=10; a<=50; a+=10)
    for (b=10; b<=50; b+=10)
      for (c=10; c<=50; c+=10)
        for (d=10; d<=50; d+=10)
	if(a!=b &&a!=c &&a!=d &&b!=c &&b!=d &&c!=d     //a,b,c,d????
	   &&(a+b==c+d)
	   &&(a+d>b+c)
	   &&(a+c<b)
	  )
	{ sort(a,b,c,d);
	  break;
          }
  return 0;
}

void sort(int a,int b,int c,int d)
{ int weight[4]={a,b,c,d};
  char surname[4]={'z','q','s','l'};
  int i,j,k,temp;
  char tempname;
  for (i=2;i>=0;i--)
    for (j=0;j<=i;j++)
       if (weight[j]<weight[j+1])//???????????????????
       { temp = weight[j];       //weight[j]?surname[j]????????????
         weight[j] = weight[j+1];
         weight[j+1] = temp;

         tempname = surname[j];
         surname[j] = surname[j+1];
         surname[j+1] = tempname;
       }
  for (k=0;k<=3;k++)
    cout <<surname[k] <<' ' <<weight[k] <<endl;
}


int main()
{
     int z,q,s,l;
	 printf("l 50\n");
          printf("q 40\n");
	 printf("z 20\n");
	 printf("s 10");

}


int main()
{
	int weight[4],k=0,i,t,w[4];
	char name[4]={'z','q','s','l'};char p;
	  for(weight[0]=1;weight[0]<=5;weight[0]++)
		for(weight[1]=1;weight[1]<=5;weight[1]++)
			if(weight[0]!=weight[1])
				for(weight[2]=1;weight[2]<=5;weight[2]++)
					if(weight[2]!=weight[0]&&weight[2]!=weight[1])
						for(weight[3]=1;weight[3]<=5;weight[3]++)
							if(weight[3]!=weight[0]&&weight[3]!=weight[1]&&weight[3]!=weight[2])
								if((weight[0]+weight[1])==(weight[2]+weight[3])&&
									(weight[0]+weight[3])>(weight[1]+weight[2])&&
									(weight[0]+weight[2])<weight[1])
									for(i=0;i<4;i++)
										w[i]=weight[i];
	for(k=1;k<=3;k++)
			for(i=0;i<=3-k;i++)
				if(w[i]<w[i+1]){
					t=w[i];
					w[i]=w[i+1];
					w[i+1]=t;
					p=name[i];
					name[i]=name[i+1];
					name[i+1]=p;}
	for(i=0;i<4;i++)
		cout<<name[i]<<' '<<w[i]*10<<endl;
	return 0;
}


int main()
{
    char a[4] = {'z', 'q', 's', 'l'}, temp1;
    int weight[4], temp;
    for (weight[0] = 10; weight[0] <= 50; weight[0] += 10)
    {
        for (weight[1] = 10; weight[1] <= 50; weight[1] += 10)
        {
            for (weight[2] = 10; weight[2] <= 50; weight[2] += 10)
            {
                weight[3] = weight[0] + weight[1] - weight [2];
                if (weight[0] + weight[3] > weight[1] + weight[2]
                    && weight[0] + weight[2] < weight[1])
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            for (int j = 0; j < 3 - i; j++)
                            {
                                if (weight[j] < weight[j + 1])
                                {
                                    temp = weight[j + 1];
                                    weight[j + 1] = weight[j];
                                    weight[j] = temp;
                                    temp1 = a[j + 1];
                                    a[j + 1] = a[j];
                                    a[j] = temp1;
                                }
                            }
                        }
                        for (int i = 0; i < 4; i++)
                        {
                            cout << a[i] << " " << weight[i] << endl;
                        }
                    }
            }
        }
    }
    return 0;
}


int main()
{
    int i, j, t;
    char m;
    int weight[4];
    char name[5] = {"zqsl"};
    for ( weight[0] = 1; weight[0] <= 5 ;weight[0]++ )
        for ( weight[1] = 1; weight[1] <= 5 ;weight[1]++ )
            for ( weight[2] = 1; weight[2] <= 5 ;weight[2]++ )
                for ( weight[3] = 1; weight[3] <= 5 ;weight[3]++ )
                    if (  (weight[3] != weight[1]) && (weight[3] != weight[0]) &&
                          (weight[3] != weight[2]) && (weight[1] != weight[0]) && (weight[2] !=
                          weight[1]) && (weight[2] != weight[0]))
                             if ((weight[0] + weight[1]) == (weight[2] + weight[3]))
                                if ((weight[0] + weight[3]) > (weight[2] + weight[1]))
                                   if ( (weight[0] + weight[2]) < weight[1] )
                                   {
                                      for ( i = 0; i < 3; i++ )
                                          for ( j = i + 1; j < 4; j++ )
                                              if ( weight[i] < weight[j] )
                                              {
                                                   t = weight[i];
                                                   weight[i] = weight[j];
                                                   weight[j] = t;
                                                   m = name[i];
                                                   name[i] = name[j];
                                                   name[j] = m;
                                              }
                                      for ( i = 0; i < 4; i++ )
                                          cout << name[i] << " " << weight[i] * 10 << endl;
                                   }
    return 0;
}


void sort(int a,int b,int c,int d)
{
	int result[4]={a,b,c,d};
	char name[4]={'z','q','s','l'};
	int temp;
	char tempname;
	for(int i=0;i<4;i++)
	{
		for(int j=i;j<4;j++)
		{
			if(result[i]<result[j])
			{
				temp=result[i];
				result[i]=result[j];
				result[j]=temp;

				tempname=name[i];
				name[i]=name[j];
				name[j]=tempname;
			}
		}
	}

	for(int i=0;i<4;i++)
	{
		cout<<name[i]<<" "<<result[i]*10<<endl;
	}
}

int main()
{
	int z,q,s,l;
	for(z=1;z<=5;z++)
	{
		for(q=1;q<=5;q++)
		{
			for(s=1;s<=5;s++)
			{
				for(l=1;l<=5;l++)
				{
					if(z+q==s+l&&z+l>s+q&&z+s<q&&z!=q!=s!=l)
					{
						sort(z,q,s,l);
					}
				}
			}
		}
	}
		return 0;
}


int main()
{
 int A,B,C,D,word,weight;
 char rank[6];
for(int j=0;j<6;j++)
 rank[j]='0';
for(A = 1; A<= 5; A++)
{
 for(B = 1; B<= 5; B++)
{
 if(A == B) continue;
  for(C = 1; C<= 5; C++)
  {
  if(A == C || B == C) continue;
  for(D =1; D<= 5; D++)
   {
    if(A == D || B == D || C == D) continue;
   word=((A+B)==(C+D))+((A+D)>(C+B))+((A+C)<B);
  if(word==3)
 {rank[A]='z';
  rank[B]='q';
  rank[C]='s';
  rank[D]='l';
 for(int j=5;j>0;j--)
  {
    if(rank[j]=='0') continue;
     else
      {cout<<rank[j]<<" ";
       weight=j*10;
       cout<<weight<<endl;}
  }}}}}}
return 0;
}


int main()
{
   int Wz,Wq,Ws,Wl,i,j;
   char rank[6];
   for(Wz=1;Wz<=5;Wz++)
   {
      for(Wq=1;Wq<=5;Wq++)
      {
         for(Ws=1;Ws<=5;Ws++)
         {
            for(Wl=1;Wl<=5;Wl++)
            {
               if((Wz+Wq==Ws+Wl)&&(Wz+Wl>Ws+Wq)&&(Wz+Ws<Wq))
               {
                   rank[Wz]='z';
                   rank[Wq]='q';
                   rank[Ws]='s';
                   rank[Wl]='l';
                   for(i=5;i>=1;i--)
                   {
                      if(rank[i]=='\0')
                      continue;
                      else cout<<rank[i]<<' '<<i*10<<endl;
                   }
               }
            }
         }
      }
   }
   return 0;
}


//
//  main.cpp
//  ???
//
//  Created by Neptune on 12-10-9.
//  Copyright (c) 2012? ??? 1200012777. All rights reserved.
//

int main()
{
    int a, b , c, d;
    for (a = 10; a <= 50; a += 10)
    {
        for (b = 10; b <= 50; b += 10)
        {
            if (a == b)
            {
                continue;
            }
            for (c = 10; c <= 50; c += 10)
            {
                if (a == c || b == c)
                {
                    continue;
                }
                for (d = 10; d <= 50; d += 10)
                {
                    if (a == d || b == d || c == d)
                    {
                        continue;
                    }
                    else if ((a + b == c + d) + (a + d > b + c) + (a + c < b ) == 3)
                    {
                        break;
                    }
                }
                if ((a + b == c + d) + (a + d > b + c) + (a + c < b ) == 3)
                    break;
            }
            if ((a + b == c + d) + (a + d > b + c) + (a + c < b ) == 3)  break;
        }
        if ((a + b == c + d) + (a + d > b + c) + (a + c < b ) == 3)
            break;
    }
    int weight[4];
    char name[4];
    weight[0] = a;
    weight[1] = b;
    weight[2] = c;
    weight[3] = d;
    name[0] = 'z';
    name[1] = 'q';
    name[2] = 's';
    name[3] = 'l';
    for (int i = 0; i < 3; i++)
    {
        for (int j = i + 1; j < 4; j++)
        {
            if (weight[j] > weight[i])
            {
                int weight_t = weight[j];
                weight[j] = weight[i];
                weight[i] = weight_t;
                int name_t = name[j];
                name[j] = name[i];
                name[i] = name_t;
            }

        }
    }

    for(int i = 0; i <= 3; i++)
    {
        cout << name[i] << " " << weight[i] << endl;
    }
    return 0;
}


int main()
{
	int z,q,s,l;
	int lastz,lastq,lasts,lastl;
	int i;
	for(z=1;z<=5;z++)
	{
		for(q=1;q<=5;q++)
		{
			if(z==q){continue;}
			for(s=1;s<=5;s++)
			{
				if(s==z||s==q){continue;}
				for(l=1;l<=5;l++)
				{
					if(l==z||l==q||l==s){continue;}
					if((z+q==s+l)&&(z+l>s+q)&&(z+s<q))
					{
						lastz=z;
						lastq=q;
						lasts=s;
						lastl=l;
					}
				}
			}
		}
	}
	for(i=5;i>=1;i--)
	{
		if(lastz==i)
		{
			lastz=10*lastz;
			cout<<"z"<<" "<<lastz<<endl;
		}
		if(lastq==i)
		{
			lastq=10*lastq;
			cout<<"q"<<" "<<lastq<<endl;
		}
		if(lasts==i)
		{
			lasts=10*lasts;
			cout<<"s"<<" "<<lasts<<endl;
		}
		if(lastl==i)
		{
			lastl=10*lastl;
			cout<<"l"<<" "<<lastl<<endl;
		}
	}
	return 0;
}