#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct Node {
    int el;
    int swapped;
    struct Node *next;
} node;
typedef node *list;

list push_back(list head_ptr, int a) {
    list block = malloc(sizeof(node)), ptr;
    block -> el = a;
    block -> next = NULL;
    if (!head_ptr) {
        return block;
    }
    ptr = head_ptr;
    while (ptr -> next)
        ptr = ptr -> next;
    ptr -> next = block;
    return head_ptr;
}

void print_list(list ptr) {
    while (ptr) {
        printf("%d ", ptr -> el);
        ptr = ptr -> next;
    }
}

void free_list(list ptr) {
    list k;
    while (ptr) {
        k = ptr;
        ptr = ptr -> next;
        free(k);
    }
}

void zero(int *arr, int n) {
    for (int i = 0; i < n; i++)
        arr[i] = 0;
}

list pop(list ptr, int *save_ptr) {
    list last = ptr;
    if (last && last -> next) {
        while (last && last -> next && last -> next -> next)
            last = last -> next;
        *save_ptr = last -> next -> el;
        free(last -> next);
        last -> next = NULL;
        return ptr;
    } else if (last && !last -> next) {
        *save_ptr = last -> el;
        free(last);
        return NULL;
    }
    *save_ptr = 0;
    return NULL;
}

int main(void) {
    list head_ptr = NULL;
    int n, a, was[101], save;
    scanf("%d", &n);
    zero(was, 101);
    for (int i = 0, j = 1; i < n; i++) {
        scanf("%d", &a);
        if (a == j) {
            head_ptr = pop(head_ptr, &save);
            printf("%d ", a);
            j++;
            while (was[a])
                j++;
            print_list(head_ptr);
            free_list(head_ptr);
            head_ptr = NULL;
            if (save != 0)
                head_ptr = push_back(head_ptr, save);
        } else {
            head_ptr = push_back(head_ptr, a);
        }
        was[a] = 1;
    }
    print_list(head_ptr);
    free_list(head_ptr);
    putchar('\n');
    return 0;
}


#include <stdio.h>

long long int t,dizi[105],n,temp;
int sa[105];
int main(){
    scanf("%I64d",&t);
    while(t--){
        memset(sa,0,sizeof(sa));
        memset(dizi,0,sizeof(dizi));
        scanf("%I64d",&n);
        for(int i=0;i<n;i++){
        	scanf("%d",&dizi[i]);
        }
        for(int i=1;i<=n;i++){
            for(int j=0;j<n;j++){
                if(dizi[j]==i){
                    for(int p=j-1;p>=0 && !sa[p] && dizi[p+1]<dizi[p];p--){
                    		temp=dizi[p];
                    		dizi[p]=dizi[p+1];
                    		dizi[p+1]=temp;
                            sa[p]=1;
                    }
                    break;
                }
            }
        }
        for(int i=0;i<n;i++){
            printf("%d ",dizi[i] );
        }
        printf("\n");
    }
return 0;
}


#include<stdio.h>

int main()
{
    int T, i, j, n, A[101], flag[101], count=0, curr, temp;
    scanf("%d", &T);
    while(T--)
    {
        scanf("%d", &n);
        for(i=1; i<=n; i++)
        {
            scanf("%d", &A[i]);
            flag[i]=0;
        }
        temp=1;
        count=1;
        while(count<=n-1 && temp<=n)
        {
            for(i=1; i<=n; i++)
            {
                if(A[i]==temp)
                {
                    break;
                }
            }
            if(i>1)
            {
                for(j=i-1;j>=1;j--)
                {
                    if(flag[j]==1)
                    {
                        break;
                    }
                    else if(A[j]<A[j+1])
                    {
                        break;
                    }
                    else
                    {
                        curr=A[j];
                        A[j]=A[j+1];
                        A[j+1]=curr;
                        flag[j]=1;
                        count++;
                    }
                }
            }
            temp++;
        }
        for(i=1; i<=n; i++)
        {
            printf("%d ", A[i]);
        }
        printf("\n");
    }
}


#include<stdio.h>
int main(){
    int q, n, ara[100],i;
    scanf("%d", &q);
    while (q--) {
        scanf("%d", &n);
        for(i = 0; i < n; i++){
            scanf("%d", &ara[i]);
        }
        int minValueFound, minValuePos, initialPos, tmp;
        initialPos = 0;
        while (1){
            minValueFound = 0;
            minValuePos = initialPos;
            for(i = initialPos; i < n; i++){
                if (ara[minValuePos] > ara[i]){
                    minValuePos = i;
                    minValueFound = 1;
                }
            }
            tmp = ara[minValuePos];
            for(i = minValuePos; i > initialPos; i--){
               ara[i] = ara[i-1];
            }
            ara[initialPos] = tmp;
            initialPos = minValuePos;

            if(!minValueFound) break;
        }

        printf("%d",ara[0]);
        for(i = 1; i < n; i++){
            printf(" %d", ara[i]);
        }
        printf("\n");
    }

    return 0;
}


#include<stdio.h>
int main(){
    int q, n, ara[100],i;
    scanf("%d", &q);
    while (q--) {
        scanf("%d", &n);
        for(i = 0; i < n; i++){
            scanf("%d", &ara[i]);
        }
        int  minValuePos, initialPos, tmp, minFound;
        initialPos = 0;

       for(i = 0; i < n; ){
           minFound = 0;
           minValuePos = i;
           for(int j = i ; j < n; j++ ){
               if(ara[minValuePos] > ara[j]){
                   minFound = 1;
                   minValuePos = j;
               }
           }

           tmp = ara[minValuePos];
           for(int j = minValuePos; j > i; j--)
               ara[j] = ara[j-1];
            ara[i] =  tmp;
           if(minFound) i = minValuePos;
           else i++;

           }

        printf("%d",ara[0]);
        for(i = 1; i < n; i++){
            printf(" %d", ara[i]);
        }
        printf("\n");
    }

    return 0;
}


#include<stdio.h>

int a[100 + 5];

void fun(int ks, int js)
{
	int t = a[js];

	for (int i = js; i > ks; i--)
	{
		a[i] = a[i - 1];
	}

	a[ks] = t;

	return;
}

int main()
{
	int q, n;

	scanf("%d", &q);
	while (q--)
	{
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d", &a[i]);

		int ks = 0;
		int js = 0;
		int min = a[ks];

		while (1)
		{
			if (ks == n - 1)
				break;

			min = a[ks];
			for (int i = ks; i < n; i++)
			{
				if (a[i] < min)
				{
					min = a[i];
					js = i;
				}
			}

			if (ks == js)
			{
				ks++;
				js++;
				continue;
			}

			fun(ks, js);

			ks = js;
		}

		for (int i = 0; i < n; i++)
			printf("%d ", a[i]);

		printf("\n");
	}

	return 0;
}


#include <stdio.h>
#include <stdlib.h>

typedef struct
{
   int index;
   int num;
}Array;

void swap(int *a,int *b)
{
    int n1,n2;
    n2=*a;
    n1=*b;
    *a=n1;
    *b=n2;
}
int main(void)
{
	int q,i,n,j,num;
	scanf("%d",&q);
	for(i=1;i<=q;i++)
	{
	    scanf("%d",&n);
	    int *input=(int*)calloc(n+1,sizeof(int));
	    int *count=(int*)calloc(n,sizeof(int));
	    Array *A=(Array*)calloc(n+1,sizeof(Array));
	    for(j=1;j<=n;j++)
	    {
	        scanf("%d",&num);
	        input[j]=num;
	        A[num].index=j;
	    }
	    for(j=1;j<=n;j++)
	    {
	        while(A[j].index>j)
	        {
	            if(count[A[j].index-1]==1)
	            {
	                break;
	            }
	            count[A[j].index-1]=1;
	            swap(input+A[j].index-1,input+A[j].index);
	            A[j].index--;

	        }
	    }
	    for(j=1;j<=n;j++)
	    {
	        printf("%d ",input[j]);
	    }
	    printf("\n");

	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

typedef struct
{
   int index;
}Array;

void swap(int *a,int *b)
{
    int n1,n2;
    n2=*a;
    n1=*b;
    *a=n1;
    *b=n2;
}
int main(void)
{
	int q,i,n,j,num;
	scanf("%d",&q);
	for(i=1;i<=q;i++)
	{
	    scanf("%d",&n);
	    int *input=(int*)calloc(n+1,sizeof(int));
	    int *count=(int*)calloc(n,sizeof(int));
	    Array *A=(Array*)calloc(n+1,sizeof(Array));
	    for(j=1;j<=n;j++)
	    {
	        scanf("%d",&num);
	        input[j]=num;
	        A[num].index=j;
	    }
	    for(j=1;j<=n;j++)
	    {
	        while(A[j].index>j)
	        {
	            if(count[A[j].index-1]==1)
	            {
	                break;
	            }
	            count[A[j].index-1]=1;
	            swap(input+A[j].index-1,input+A[j].index);
	            A[j].index--;

	        }
	    }
	    for(j=1;j<=n;j++)
	    {
	        printf("%d ",input[j]);
	    }
	    printf("\n");

	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

typedef struct
{
   int index;
}Array;

void swap(int *a,int *b)
{
    int n1,n2;
    n2=*a;
    n1=*b;
    *a=n1;
    *b=n2;
}
int main(void)
{
	int q,i,n,j,num;
	scanf("%d",&q);
	for(i=1;i<=q;i++)
	{
	    scanf("%d",&n);
	    int *input=(int*)calloc(n+1,sizeof(int));
	    int *count=(int*)calloc(n,sizeof(int));
	    Array *A=(Array*)calloc(n+1,sizeof(Array));
	    for(j=1;j<=n;j++)
	    {
	        scanf("%d",&num);
	        input[j]=num;
	        A[num].index=j;
	    }
	    for(j=1;j<=n;j++)
	    {
	        while(A[j].index>j)
	        {
	            if(count[A[j].index-1]==1)
	            {
	                break;
	            }
	            else if(input[A[j].index-1]<input[A[j].index])
	            {
	                break;
	            }
	            count[A[j].index-1]=1;
	            swap(input+A[j].index-1,input+A[j].index);
	            A[j].index--;

	        }
	    }
	    for(j=1;j<=n;j++)
	    {
	        printf("%d ",input[j]);
	    }
	    printf("\n");

	}
	return 0;
}


#include<stdio.h>

int mini(int arr[],int i,int n)
{
    int j;
    int ans=i;
    for(j=i;j<n;j++)
    {
        if(arr[j]<arr[ans])
        ans=j;
    }
    return ans;
}

void swap(int arr[],int i)
{
    int temp;
    temp=arr[i];
    arr[i]=arr[i+1];
    arr[i+1]=temp;
}
void printa(int arr[],int n)
{
    for(int i=0;i<n;i++)
    printf("%d",arr[i]);

    printf("\n");
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int n;
        scanf("%d",&n);

        int arr[n],i;

        for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
        i=0;
        int m=0;
        int j;
        while(i!=n-1)
        {
            m=mini(arr,i,n);
            if(m==i)
            {
                i++;
                continue;
            }
            for(j=m-1;j>=i;j--)
            {
                swap(arr,j);

            }
            i=m;

        }
        printa(arr,n);
    }
    return 0;
}


#include<stdio.h>
void swap(int arr[],int i)
{
int temp;
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
void printa(int arr[],int n)
{
	int i;
	for(i=0;i<n;i++)
		printf("%d",arr[i]);
	printf("\n");
}

int main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int i;
		int n;
		scanf("%d",&n);
		int arr[n];
		for(i=0;i<n;i++)
			scanf("%d",&arr[i]);

//		printa(arr,n);
		int a=0;
	for(int k=0; k<n;k++)
	{

		for(i=0;i<n;i++)
		{
			if(arr[i]==k+1)
			{
		//		printf("ispe break  hua arr[%d]==%d+1\n",i,k);
				break;
			}

		}
		int j;
		int sig=0;
		for(j=i-1;j>=a;j--)
		{
			swap(arr ,j);
			sig=1;
		//	printf("yeh swap hue %d aur %d\n",j,j+1);
		}
	//	printa(arr,n);
		if(sig)
		a=i;
		else
		a++;
	}
		printa(arr,n);
	}
	return 0;
}


#include<stdio.h>

int mini(int arr[],int i,int n)
{
    int j;
    int ans=i;
    for(j=i;j<n;j++)
    {
        if(arr[j]<arr[ans])
        ans=j;
    }
    return ans;
}

void swap(int arr[],int i)
{
    int temp;
    temp=arr[i];
    arr[i]=arr[i+1];
    arr[i+1]=temp;
}
void printa(int arr[],int n)
{
    for(int i=0;i<n;i++)
    printf("%d ",arr[i]);

    printf("\n");
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int n;
        scanf("%d",&n);

        int arr[n],i;

        for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
        i=0;
        int m=0;
        int j;
        while(i!=n-1)
        {
            m=mini(arr,i,n);
            if(m==i)
            {
                i++;
                continue;
            }
            for(j=m-1;j>=i;j--)
            {
                swap(arr,j);

            }
            i=m;

        }
        printa(arr,n);
    }
    return 0;
}


#include<stdio.h>

int mini(int arr[],int i,int n)
{
    int j;
    int ans=i;
    for(j=i;j<n;j++)
    {
        if(arr[j]<arr[ans])
        ans=j;
    }
    return ans;
}

void swap(int arr[],int i)
{
    int temp;
    temp=arr[i];
    arr[i]=arr[i+1];
    arr[i+1]=temp;
}
void printa(int arr[],int n);
{
    for(int i=0;i<n;i++)
    printf("%d",arr[i]);

    printf("\n");
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int n;
        scanf("%d",&n);

        int arr[n],i;

        for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
        i=0;
        int m=0;
        int j;
        while(i!=n-1)
        {
            m=mini(arr,i,n);
            if(m==i)
            {
                i++;
                continue;
            }
            for(j=m-1;j>=i;j--)
            {
                swap(arr,j);

            }
            i=m;

        }
        printa(arr,n);
    }
    return 0;
}


#include<stdio.h>
void swap(int arr[],int i)
{
int temp;
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
void printa(int arr[],int n)
{
	int i;
	for(i=0;i<n;i++)
		printf("%d ",arr[i]);
	printf("\n");
}

int main()
{
	int q;
	scanf("%d",&q);
	while(q--)
	{
		int i;
		int n;
		scanf("%d",&n);
		int arr[n];
		for(i=0;i<n;i++)
			scanf("%d",&arr[i]);

//		printa(arr,n);
		int a=0;
	for(int k=0; k<n;k++)
	{

		for(i=0;i<n;i++)
		{
			if(arr[i]==k+1)
			{
		//		printf("ispe break  hua arr[%d]==%d+1\n",i,k);
				break;
			}

		}
		int j;
		int sig=0;
		for(j=i-1;j>=a;j--)
		{
			swap(arr ,j);
			sig=1;
		//	printf("yeh swap hue %d aur %d\n",j,j+1);
		}
	//	printa(arr,n);
		if(sig)
		a=i;
		else
		a++;
	}
		printa(arr,n);
	}
	return 0;
}


#include<stdio.h>

int mini(int arr[],int i,int n)
{
    int j;
    int ans=i;
    for(j=i;j<n;j++)
    {
        if(arr[j]<arr[ans])
        ans=j;
    }
    return ans;
}

void swap(int arr[],int i)
{
    int temp;
    temp=arr[i];
    arr[i]=arr[i+1];
    arr[i+1]=temp;
}
printa(int arr[],int n);
{
    for(int i=0;i<n;i++)
    printf("%d",arr[i]);

    printf("\n");
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        int n;
        scanf("%d",&n);

        int arr[n],i;

        for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
        i=0;
        int m=0;
        int j;
        while(i!=n-1)
        {
            m=mini(arr,i,n);
            if(m==i)
            {
                i++;
                continue;
            }
            for(j=m-1;j>=i;j--)
            {
                swap(arr,j);

            }
            i=m;

        }
        printa(arr,n);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string str,res;
		cin>>str;
		int hash[26]={0};
		for(int i=0;i<str.size();i++)
		{
			hash[str[i]-'a']++;
		}
		for(int i=0;i<26;i++)
		{
			if(hash[i]%2!=0)
			{
				res+=('a'+i);
			}
		}
		cout<<res<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string str,res;
		cin>>str;
		if(str.size()==1)
		{
			cout<<str<<endl;
		}
		else
	{

		int hash[26]={0};
		for(int i=0;i<str.size();i++)
		{
			if(str[i]!=str[i-1] && str[i]!=str[i+1] && hash[str[i]-'a']!=1)
			{
				hash[str[i]-'a']=1;
			}
		}
		for(int i=0;i<26;i++)
		{
			if(hash[i]==1)
			{
				res+=(i+'a');
			}
		}
		cout<<res<<endl;
	}
	}
}


#include<bits/stdc++.h>
using namespace std;

main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string str,res;
		cin>>str;
		if(str.size()==1)
		{
			cout<<str<<endl;
		}
		else
	{

		int hash[26]={0};
		if(str[0]!=str[1])
		{
			hash[str[0]-'a']=1;
		}
		for(int i=1;i<str.size();i++)
		{
			if(str[i]!=str[i-1] && str[i]!=str[i+1])
			{
				hash[str[i]-'a']=1;
			}
			else if(hash[str[i]-'a']!=1)
			{
				hash[str[i]-'a']=0;
			}
		}
		for(int i=0;i<26;i++)
		{
			if(hash[i]==1)
			{
				res+=(i+'a');
			}
		}
		cout<<res<<endl;
	}
	}
}


#include<bits/stdc++.h>
using namespace std;

main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string str,res;
		int count[26]={0};
		cin>>str;
		if(str.size()==1)
		{
			cout<<str<<endl;
		}
		else
		{
			int i;
			for(i=0;i<str.size()-1;i++)
			{
				count[str[i]-'a']++;
				if(str[i]!=str[i+1])
				{
					if(count[str[i]-'a']%2==1)
					{
						res+=str[i];
					}
					count[str[i]-'a']=0;
				}
			}
			count[str[i]-'a']++;
			if(count[str[i]-'a']%2==1)
			{
				res+=str[i];
			}
			sort(res.begin(),res.end());
			cout<<res<<endl;
		}

	}
}


#include<bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);};
}
template<class t> inline void writeln(t x){
	write(x);putchar('\n');
	return;
}
int t;
int main(){
	read(t);
	while(t--){
		string s;
		string ans;
		cin>>s;
		if(s[0]!=s[1]){
			ans+=s[0];
		}
		for(int i=1;i<s.size();i++){
			if(s[i]!=s[i-1] && s[i]!=s[i+1]){
				ans+=s[i];
			}
		}
		sort(ans.begin(),ans.end());
		for(int i=0;i<ans.size();i++){
			cout<<ans[i];
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);};
}
template<class t> inline void writeln(t x){
	write(x);putchar('\n');
	return;
}
int t;
int main(){
	read(t);
	while(t--){
		string s;
		string ans;
		cin>>s;
		if(s[0]!=s[1]){
			ans+=s[0];
		}
		for(int i=1;i<=s.size();i++){
			if(s[i]!=s[i-1] && s[i]!=s[i+1]){
				ans+=s[i];
			}
		}
		sort(ans.begin(),ans.end());
		for(int i=0;i<=ans.size();i++){
			cout<<ans[i];
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);};
}
template<class t> inline void writeln(t x){
	write(x);putchar('\n');
	return;
}
int t;
map<char,bool>ma;
int main(){
	read(t);
	while(t--){
		string s;
		string ans;
		cin>>s;
		if(s[0]!=s[1]){
			ans+=s[0];
			ma[s[0]]=1;
		}
		int num=1;
		for(int i=1;i<s.size();i++){
			if(s[i]!=s[i-1] && s[i]!=s[i+1] && ma[s[i]]==0){
				ans+=s[i];
				ma[s[i]]=1;
			}else{
				if(ma[s[i]]==0){
					if(s[i]==s[i+1]){
						num++;
					}else{
						if(num%2==1 && num!=1){
							ma[s[i-1]]=1;
							ans+=s[i-1];

						}
						num=1;
					}
				}

			}
		}
		sort(ans.begin(),ans.end());

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


#include<bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);};
}
template<class t> inline void writeln(t x){
	write(x);putchar('\n');
	return;
}
int t;
map<char,bool>ma;
int main(){
	read(t);
	while(t--){
		string s;
		string ans;
		cin>>s;
		int num=1;

		for(int i=0;i<s.size();i++){
			if(s[i]!=s[i-1] && s[i]!=s[i+1] && ma[s[i]]==0){
				ans+=s[i];
				ma[s[i]]=1;
			}else{
				if(ma[s[i]]==0){
					if(s[i]==s[i+1]){
						num++;
					}else{
						if(num%2==1 && num!=1){
							ma[s[i-1]]=1;
							ans+=s[i-1];

						}
						num=1;
					}
				}

			}
		}
		sort(ans.begin(),ans.end());

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


#include<bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);};
}
template<class t> inline void writeln(t x){
	write(x);putchar('\n');
	return;
}
int t;
map<char,bool>ma;
int main(){
	read(t);
	while(t--){
		string s;
		string ans;
		ma.clear();
		cin>>s;
		int num=1;
		for(int i=0;i<s.size();i++){
			if(s[i]!=s[i-1] && s[i]!=s[i+1] && ma[s[i]]==0){
				ans+=s[i];
				ma[s[i]]=1;
			}else{
				if(ma[s[i]]==0){
					if(s[i]==s[i+1]){
						num++;
					}else{
						if(num%2==1 && num!=1){
							ma[s[i-1]]=1;
							ans+=s[i-1];

						}
						num=1;
					}
				}

			}
		}
		sort(ans.begin(),ans.end());
		for(int i=0;i<ans.size();i++){
			cout<<ans[i];
		}
		cout<<endl;
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        if(length!=0)
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        ans[0]='1';
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&num%2!=0)
            {
                ans[index]=s[i];
                index++;
            }
        }
        if(index==0)
        {
            printf("\n");
            continue;
        }
        ans[index]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        ans[0]='1';
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index+1]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        if(ans[0]!='1')
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        else printf(" ");
        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        ans[0]='1';
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        if(ans[0]!='1')
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        else printf("\0");
        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index]='\0';
        length = strlen(ans);
        for(int i=0;i<length;i++) printf("%c",ans[i]);
        printf("\n");
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        printf("\n");

    }
    return 0;
}
//最开始的(连续)字符出现bug


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        ans[0]='1';
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        if(ans[0]!='1')
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        ans[0]='1';
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        if(ans[0]!='1')
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        else printf(" ");
        printf("\n");

    }
    return 0;
}


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        ans[index]='\0';
        length = strlen(ans);
        //for(int i=0;i<length;i++) printf("%c",ans[i]);
        printf("\n");
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        printf("\n");

    }
    return 0;
}
//最开始的(连续)字符出现bug


#include <stdio.h>
#include <string.h>
int Partition(char arr[],int left,int right)
{
    int base = arr[left];
    while(left<right)
    {
        while(left<right && base<arr[right]) right --;
        arr[left] = arr[right];
        while(left<right && arr[left]<=base) left ++;
        arr[right] = arr[left];
    }
    arr[left] = base;
    return left;
}
void QuickSort(char arr[],int left,int right)
{
    if(left<right)
    {
        int position = Partition(arr,left,right);
        QuickSort(arr,left,position-1);
        QuickSort(arr,position+1,right);
    }
    return;
}
int main()
{
    int q;
    scanf("%d",&q);
    while(q--)
    {
        char s[505],ans[505];
        ans[0]='1';
        scanf("%s",s);
        int length=strlen(s),num=1,index=0;
        if(length==1)
        {
            printf("%c\n",s[0]);
            continue;
        }
        for(int i=1;i<length;i++)
        {
            if(s[i]!=s[i-1])
            {
                if(num%2!=0)
                {
                    ans[index]=s[i-1];
                    index++;
                }
                num=1;
            }
            else num++;
            if(i==length-1&&s[i]!=s[i-1])
                {
                    ans[index]=s[i];
                    index++;
                }
        }
        if(index==0)
        {
            printf("\n");
            continue;
        }
        ans[index]='\0';
        length = strlen(ans);
        QuickSort(ans,0,length-1);
        printf("%c",ans[0]);
        for(int i=1;i<length;i++)
        {
            if(ans[i]==ans[i-1]) continue;
            else printf("%c",ans[i]);
        }
        printf("\n");

    }
    return 0;
}


using namespace std;
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <set>

void findOkKey(string s) {
	//cout << s << endl;
	set<char> my_set;
	set<char>::iterator it;

	if(s.length() == 0) {
		cout << endl;
		return;
	}

	int idx = 0;
	int streak = 0;
	//char prev;
	char prev = s[idx++];
	streak++;

	while(idx < s.length()) {
		/*if(streak == 0) {
			prev = s[idx];
			streak++;
		}*/
		if(s[idx] != prev) { //&& my_set.find(prev) != my_set.end()) {
			if(streak % 2 == 1) {
				my_set.insert(prev);
			}
			prev = s[idx];
			streak = 1;
		} else {
			streak++;
		}
		idx++;
	}
	if(streak == 1) my_set.insert(prev);

	for(it = my_set.begin(); it!=my_set.end(); ++it) {
		cout << *it;
	}
	cout << endl;

}

int main(int argc, char** argv) {
	int T;
	int a, b, c, d, k;
	string s;

	cin >> T;

	while(T > 0) {
		cin >> s;

		findOkKey(s);

		T--;
	}

}


using namespace std;
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <set>

void findOkKey(string s) {
	//cout << s << endl;
	set<char> my_set;
	set<char>::iterator it;

	int idx = 0;
	int streak = 0;
	//char prev;
	char prev = s[idx++];
	streak++;

	while(idx < s.length()) {
		/*if(streak == 0) {
			prev = s[idx];
			streak++;
		}*/
		if(s[idx] != prev) { //&& my_set.find(prev) != my_set.end()) {
			if(streak == 1) {
				my_set.insert(prev);
			}
			prev = s[idx];
			streak = 1;
		} else {
			streak++;
		}
		idx++;
	}
	if(streak == 1) my_set.insert(prev);

	for(it = my_set.begin(); it!=my_set.end(); ++it) {
		cout << *it;
	}
	cout << endl;

}

int main(int argc, char** argv) {
	int T;
	int a, b, c, d, k;
	string s;

	cin >> T;

	while(T > 0) {
		cin >> s;

		findOkKey(s);

		T--;
	}

}


using namespace std;
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <set>

void findOkKey(string s) {
	//cout << s << endl;
	set<char> my_set;
	set<char>::iterator it;

	int idx = 0;
	int streak = 0;
	//char prev;
	char prev = s[idx++];
	streak++;

	while(idx < s.length()) {
		/*if(streak == 0) {
			prev = s[idx];
			streak++;
		}*/
		if(s[idx] != prev) { //&& my_set.find(prev) != my_set.end()) {
			if(streak % 2 == 1) {
				my_set.insert(prev);
			}
			prev = s[idx];
			streak = 1;
		} else {
			streak++;
		}
		idx++;
	}
	if(streak == 1) my_set.insert(prev);

	for(it = my_set.begin(); it!=my_set.end(); ++it) {
		cout << *it;
	}
	cout << endl;

}

int main(int argc, char** argv) {
	int T;
	int a, b, c, d, k;
	string s;

	cin >> T;

	while(T > 0) {
		cin >> s;

		findOkKey(s);

		T--;
	}

}


using namespace std;
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <set>

void findOkKey(string s) {
	//cout << s << endl;
	set<char> my_set;
	set<char>::iterator it;

	if(s.length() == 0) {
		cout << endl;
		return;
	}

	int idx = 0;
	int streak = 0;
	//char prev;
	char prev = s[idx++];
	streak++;

	while(idx < s.length()) {
		/*if(streak == 0) {
			prev = s[idx];
			streak++;
		}*/
		if(s[idx] != prev) { //&& my_set.find(prev) != my_set.end()) {
			if(streak % 2 == 1) {
				my_set.insert(prev);
			}
			prev = s[idx];
			streak = 1;
		} else {
			streak++;
		}
		idx++;
	}
	if(streak % 2 == 1) my_set.insert(prev);

	for(it = my_set.begin(); it!=my_set.end(); ++it) {
		cout << *it;
	}
	cout << endl;

}

int main(int argc, char** argv) {
	int T;
	int a, b, c, d, k;
	string s;

	cin >> T;

	while(T > 0) {
		cin >> s;

		findOkKey(s);

		T--;
	}

}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		for(int i = 0;i < len;i++){
			mp[s[i]]++;
		}
		map<char,int>::iterator it;
		for(it = mp.begin();it != mp.end();it++){
			int tmp = it->second;
			char hh = it->first;
			if(tmp % 2 == 1) ans += hh;
		}
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		for(int i = 0;i < len;i++){
			mp[s[i]]++;
		}
		map<char,int>::iterator it;
		for(it = mp.begin();it != mp.end();it++){
			int tmp = it->second;
			char hh = it->first;
			if(tmp % 2 == 1) ans += hh;
			else{
				int ok = 0;
				for(int i = 0;i < len;i++){
					if(s[i] == hh){
						if(s[i - 1] != hh&&s[i + 1] != hh){
							ok = 1;
							break;
						}
					}
				}
				if(ok) ans += hh;
			}
		}
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		for(int i = 0;i < len - 1;){
			if(s[i] != s[i + 1]&&!mp[s[i]]){
				ans += s[i];
				mp[s[i]]++;
				i++;
			}
			else i = i  + 2;
		}
		//if(s[len - 1] != s[len - 2]&&!mp[s[len - 1]]) ans += s[len - 1];
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		for(int i = 0;i < len - 1;){
			if(s[i] != s[i + 1]&&!mp[s[i]]){
				ans += s[i];
				mp[s[i]]++;
				i++;
			}
			else i = i  + 2;
		}
		if(s[len - 1] != s[len - 2]&&!mp[s[len - 1]]) ans += s[len - 1];
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s = "";
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		for(int i = 0;i < len;i++){
			mp[s[i]]++;
		}
		map<char,int>::iterator it;
		for(it = mp.begin();it != mp.end();it++){
			int tmp = it->second;
			char hh = it->first;
			if(tmp % 2 == 1) ans += hh;
		}
		sort(ans.begin(),ans.end());
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s = "";
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		if(len == 1){
			cout << s << endl;
			continue;
		}
		for(int i = 0;i < len;){
			if(s[i] != s[i + 1]){
				if(!mp[s[i]]){
				ans += s[i];
				mp[s[i]]++;
				//cout << s[i] << endl;
				}
				i++;
			}
			else i += 2;
		}
		//if(s[len - 1] != s[len - 2]&&!mp[s[len - 1]]) ans += s[len - 1];
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		for(int i = 0;i < len;){
			if(s[i] != s[i + 1]&&!mp[s[i]]){
				ans += s[i];
				mp[s[i]]++;
				i++;
			}
			else i = i  + 2;
		}
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		if(len == 1){
			cout << s << endl;
			continue;
		}
		for(int i = 0;i < len;){
			if(s[i] != s[i + 1]&&!mp[s[i]]){
				ans += s[i];
				mp[s[i]]++;
				//cout << s[i] << endl;
				i++;
			}
			else i += 2;
		}
		//if(s[len - 1] != s[len - 2]&&!mp[s[len - 1]]) ans += s[len - 1];
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string s;
		cin >> s;
		string ans = "";
		mp.clear();
		int len = s.length();
		if(len == 1){
			cout << s << endl;
			continue;
		}
		for(int i = 0;i < len;){
			if(s[i] != s[i + 1]){
				if(!mp[s[i]]){
				ans += s[i];
				mp[s[i]]++;
				//cout << s[i] << endl;
				i++;
				}
			}
			else i += 2;
		}
		//if(s[len - 1] != s[len - 2]&&!mp[s[len - 1]]) ans += s[len - 1];
		sort(ans.begin(),ans.end());
		cout << ans;
		cout << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
         vector<char>v1;
        getline(cin,s);
        int S=s.length();
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
        if(v.empty())
        {
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size()-1;p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
         vector<char>v1;
        getline(cin,s);
        int S=s.length();
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
        if(!v.empty())
        {
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size()-1;p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        string s;
        vector<char>v;
        vector<char>v1;
        cin>>s;
        int i;
        S=s.length();
        for( i=0;i<S-1;)
        {
            int j=i+1;
            int f=0;
            while(s[i]==s[j] && j<S)
            {
                j++;
                f++;
            }
            if(f%2==0)
            {
                v.push_back(s[i]);
            }
            i=j;

        }
        if(i<S)
        v.push_back(s[S-1]);
        sort(v.begin(),v.end());
        int q;
        for(int q=0;q<v.size();q++)
        {
            if(v[q]!=v[q+1])
            v1.push_back(v[q]);
        }
        v1.push_back(v[q-1]);

        if(v1.empty())
        {
            cout<<" "<<endl;
        }
        else
        {

        for(int d=0;d<v1.size();d++)
        {
            cout<<v1[d];
        }
        }
        cout<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
         vector<char>v1;
        getline(cin,s);
        int S=s.length();
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size();p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);
    if(!v1.empty())
    {

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        string s;
        vector<char>v;
        vector<char>v1;
        cin>>s;
        int i;
       int  S=s.length();
        for( i=0;i<S-1;)
        {
            int j=i+1;
            int f=0;
            while(s[i]==s[j] && j<S)
            {
                j++;
                f++;
            }
            if(f%2==0)
            {
                v.push_back(s[i]);
            }
            i=j;

        }
        if(i<S)
        v.push_back(s[S-1]);
        sort(v.begin(),v.end());
        int q;
        for(int q=0;q<v.size()-1;q++)
        {
            if(v[q]!=v[q+1])
            v1.push_back(v[q]);
        }
        v1.push_back(v[v.size()-1]);

        if(v1.empty())
        {
            cout<<" "<<endl;
        }
        else
        {

        for(int d=0;d<v1.size();d++)
        {
            cout<<v1[d];
        }
        }
        cout<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        string s;
        vector<char>v;
        vector<char>v1;
        cin>>s;
        int i;
       int  S=s.length();
        for( i=0;i<S;)
        {
            int j=i;
            int f=0;
            while(s[i]==s[j] && j<S)
            {
                j++;
                f++;
            }
            if(f%2!=0)
            {
                v.push_back(s[i]);
            }
            i=j;

        }
        // if(i<S)
        // v.push_back(s[S-1]);
        sort(v.begin(),v.end());
        int q;
        for(int q=0;q<v.size()-1;q++)
        {
            if(v[q]!=v[q+1])
            v1.push_back(v[q]);
        }
        v1.push_back(v[v.size()-1]);

        if(v1.empty())
        {
            cout<<" "<<endl;
        }
        else
        {

        for(int d=0;d<v1.size();d++)
        {
            cout<<v1[d];
        }
        }
        cout<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        string s;
        vector<char>v;
        vector<char>v1;
        cin>>s;
        int i;
       int  S=s.length();
        for( i=0;i<S-1;)
        {
            int j=i+1;
            int f=0;
            while(s[i]==s[j] && j<S)
            {
                j++;
                f++;
            }
            if(f%2==0)
            {
                v.push_back(s[i]);
            }
            i=j;

        }
        if(i<S)
        v.push_back(s[S-1]);
        sort(v.begin(),v.end());
        int q;
        for(int q=0;q<v.size()-1;q++)
        {
            if(v[q]!=v[q+1])
            v1.push_back(v[q]);
        }
        v1.push_back(v[q-1]);

        if(v1.empty())
        {
            cout<<" "<<endl;
        }
        else
        {

        for(int d=0;d<v1.size();d++)
        {
            cout<<v1[d];
        }
        }
        cout<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        string s;
        vector<char>v;
        vector<char>v1;
        cin>>s;
        int i;
       int  S=s.length();
        for( i=0;i<S-1;)
        {
            int j=i+1;
            int f=0;
            while(s[i]==s[j] && j<S)
            {
                j++;
                f++;
            }
            if(f%2==0)
            {
                v.push_back(s[i]);
            }
            i=j;

        }
        if(i<S)
        v.push_back(s[S-1]);
        sort(v.begin(),v.end());
        int q;
        for(int q=0;q<v.size();q++)
        {
            if(v[q]!=v[q+1])
            v1.push_back(v[q]);
        }
        v1.push_back(v[q-1]);

        if(v1.empty())
        {
            cout<<" "<<endl;
        }
        else
        {

        for(int d=0;d<v1.size();d++)
        {
            cout<<v1[d];
        }
        }
        cout<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
        getline(cin,s);
        int S=sizeof(s);
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
    if(!v.empty())
    {
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++)
        {
            cout<<v[i];
        }

        cout<<endl;
    }
    else
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int S=s.length();
         vector<char>v;
         vector<char>v1;
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[(int)s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[(int)s[i]]%2!=0)
            v.push_back(s[i]);
        }
        if(!v.empty())
        {
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size()-1;p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else if(v.empty())
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        getline(cin,s);
        int S=s.length();
         vector<char>v;
         vector<char>v1;
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[(int)s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[(int)s[i]]%2!=0)
            v.push_back(s[i]);
        }
        if(!v.empty())
        {
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size()-1;p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else if(v.empty())
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {

        string s;
        vector<char>v;
        vector<char>v1;
        cin>>s;
        int i;
       int  S=s.length();
        for( i=0;i<S;)
        {
            int j=i;
            int f=0;
            while(s[i]==s[j] && j<S)
            {
                j++;
                f++;
            }
            if(f%2!=0)
            {
                v.push_back(s[i]);
            }
            i=j;

        }

      if(!v.empty())
      {

        sort(v.begin(),v.end());
        int q;
        for(int q=0;q<v.size()-1;q++)
        {
            if(v[q]!=v[q+1])
            v1.push_back(v[q]);
        }
        v1.push_back(v[v.size()-1]);

        for(int d=0;d<v1.size();d++)
        {
            cout<<v1[d];
        }
      }

       else
        {
            cout<<" ";
        }

        cout<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
         vector<char>v1;
        getline(cin,s);
        int S=s.length();
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
        if(v.empty())
        {
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size();p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
         vector<char>v1;
        getline(cin,s);
        int S=s.length();
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
        if(!v.empty())
        {
        sort(v.begin(),v.end());
        int p,q=0;
        for(int p=0;p<v.size()-1;p++)
        {
            if(v[p]!=v[p+1])
            {
                v1.push_back(v[p]);
            }
        }
        v1.push_back(v[v.size()-1]);

        for(int i=0;i<v1.size();i++)
        {
            cout<<v1[i];
        }

        cout<<endl;
    }
    else if(v.empty())
    cout<<" "<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;;
    cin>>t;
    while(t--)
    {
        string s;
        vector<char>v;
        getline(cin,s);
        int S=s.length();
        char fr[999999]={0};
        for(int i=0;i<S;i++)
        {
            fr[s[i]]++;
        }

        for(int i=0;i<S;i++)
        {
            if(fr[s[i]]%2!=0)
            v.push_back(s[i]);
        }
    if(!v.empty())
    {
        sort(v.begin(),v.end());
        for(int i=0;i<v.size();i++)
        {
            cout<<v[i];
        }

        cout<<endl;
    }
    else
    cout<<" "<<endl;

    }
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int tst;
	cin>>tst;
	while(tst--){
		string s;
		cin>>s;
		int sz = s.size();
		vector<char> v;
		for(int i = 0 ; i < sz ; ++i){
			int j = i ;
			while(j+1 < sz && s[j+1] == s[i])++j;
			if((j-i+1) & 1)v.push_back(s[i]);
			i = j;
		}
		sort(v.begin(),v.end());
		for(char x : v)putchar(x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int tst;
	cin>>tst;
	while(tst--){
		string s;
		cin>>s;
		int sz = s.size();
		set<char> v;
		for(int i = 0 ; i < sz ; ++i){
			int j = i ;
			while(j+1 < sz && s[j+1] == s[i])++j;
			if((j-i+1) & 1)v.insert(s[i]);
			i = j;
		}
		//sort(v.begin(),v.end());
		for(char x : v)putchar(x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int tst;
	cin>>tst;
	while(tst--){
		string s;
		cin>>s;
		int siz = s.length();
		if(siz == 1){
			putchar(s[0]);
			puts("");
			continue;
		}
		vector<char> v;
		int cnt = 1 ;
		for(int i = 0 ; i < s.length() ; ++i){
			if(i == s.length()-1 && s[i] != s[i-1])v.push_back(s[i]);
			else if(s[i] == s[i+1])++cnt;
			else if(s[i] != s[i-1]){
				if(cnt % 2 != 0)v.push_back(s[i]);
				cnt = 1;
			}
		}
		sort(v.begin(),v.end());
		for(char x : v)putchar(x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int tst;
	cin>>tst;
	while(tst--){
		string s;
		cin>>s;
		map<char,int> mp;
		for(int i = 0 ; s[i] != '\0' ; ++i)mp[s[i]]++;
		for(auto x : mp)if((x.second & 1))putchar(x.first);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int tst;
	cin>>tst;
	while(tst--){
		string s;
		cin>>s;
		map<char,int> mp;
		vector<char> v;
		for(int i = 0 ; s[i] != '\0' ; ++i)mp[s[i]]++;
		//for(int i = 0 ; i < s.size()-1 ; ++i)if(s[i] == s[i+1] && find(v.begin(),v.end(),s[i]) == v.end())v.push_back(s[i]);
		for(auto x : mp)if((x.second & 1))v.push_back(x.first);
		sort(v.begin(),v.end());
		for(char o : v)putchar(o);
		puts("");
	}
	return 0;
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int>vi;
int n,m,k,t;
ll sum;
string s;
map<char, int> mp;
int main()
{
    ios::sync_with_stdio(0);
    cin>>t;
    while(t--)
    {
        cin>>s;
        mp.clear();
        for(int i=0; i<s.size(); i++)
        {
            mp[s[i]]++;
        }
        map<char, int>::iterator itr=mp.begin();
        while(itr!=mp.end())
        {
            if(((itr->second)!=0)&&((itr->second)%2==1))
                cout<<itr->first;
            itr++;
        }
        cout<<endl;

    }
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int>vi;
int n,m,k,t;
ll sum;
string s;
map<char, int> mp;
int main()
{
    ios::sync_with_stdio(0);
    cin>>t;
    while(t--)
    {
        mp.clear();
        cin>>s;
        for(int i=0; i<s.size(); i++)
        {
            int j=i+1;
            mp[s[i]]++;
            while(s[i]==s[j]&&j<s.size())
            {
                mp[s[i]]++;
                j++;

            }
        }
        map<char, int>::iterator itr=mp.begin();
        while(itr!=mp.end())
        {
            if(((itr->second)==1)||((itr->second)%2==0))
                cout<<itr->first;
            itr++;
        }
        cout<<endl;

    }
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int>vi;
int n,m,k,t;
ll sum;
string s;
map<char, int> mp;
int main()
{
    ios::sync_with_stdio(0);
    cin>>t;
    while(t--)
    {
        cin>>s;
        mp.clear();
        for(int i=0; i<s.size(); i++)
        {
            mp[s[i]]++;
        }
        map<char, int>::iterator itr=mp.begin();
        while(itr!=mp.end())
        {
            if((itr->second)%2==1)
                cout<<itr->first;
            itr++;
        }
        cout<<endl;

    }
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int>vi;
int n,m,k,t;
ll sum,cnt;
string s;
set<char>st;
int main()
{
    ios::sync_with_stdio(0);
    cin>>t;
    while(t--)
    {
        st.clear();
        cin>>s;
        for(int i=0; i<s.size(); i++)
        {
            int j=i;
            cnt=1;
            while(s[i]==s[j+1]&&j<s.size())
            {
                j++;
                cnt++;
            }
            if(cnt%2!=0)
                st.insert(s[i]);
            i=j;
        }
        set<char>::iterator itr=st.begin();
        while(itr!=st.end())
        {
            cout<<*itr;
            itr++;
        }
        cout<<endl;

    }
}


//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int>vi;
int n,m,k,t;
ll sum;
string s;
map<char, int> mp;
int main()
{
    ios::sync_with_stdio(0);
    cin>>t;
    while(t--)
    {
        cin>>s;
        mp.clear();
        for(int i=0; i<s.size(); i++)
        {
            mp[s[i]]++;
        }
        map<char, int>::iterator itr=mp.begin();
        while(itr!=mp.end())
        {
            if(((itr->second)!=0)&&((itr->second)%2!=0))
                cout<<itr->first;
            itr++;
        }
        cout<<endl;

    }
}


#include<iostream>
#include<cstring>
using namespace std;
int main() {
    int n,w[30];
    cin>>n;
    for (int i=0;i<n;++i) {
        for (int j=0;j<26;++j)
            w[j]=1;
        string s;
        cin>>s;
        s=' '+s+' ';
        int t=s.length()+1;
        for (int j=1;j<t;++j) {
            if (s[j]!=s[j-1] && s[j]!=s[j+1])
                w[s[j]-'a']=0;
        }
        for (int j=0;j<26;++j)
            if (!w[j])
                putchar ('a'+j);
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main() {
    int n,w[30];
    cin>>n;
    for (int i=0;i<n;++i) {
        for (int j=0;j<26;++j)
            w[j]=1;
        string s;
        cin>>s;
        int t=s.length();
        if (s[0]!=s[1])
            w[s[0]-'a']=0;
        if (s[t-2]!=s[t-1])
            w[s[t-1]-'a']=0;
        for (int j=1;j<t-1;++j) {
            if (s[j]!=s[j-1] && s[j]!=s[j+1])
                w[s[j]-'a']=0;
        }
        for (int j=0;j<26;++j)
            if (!w[j])
                putchar ('a'+j);
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main() {
    int n,w[30];
    cin>>n;
    for (int i=0;i<n;++i) {
        for (int j=0;j<26;++j)
            w[j]=1;
        string s;
        cin>>s;
        s=' '+s+' ';
        int t=s.length();
        for (int j=1;j<t;++j) {
            if (s[j]!=s[j-1] && s[j]!=s[j+1])
                w[s[j]-'a']=0;
        }
        for (int j=0;j<26;++j)
            if (!w[j])
                putchar ('a'+j);
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main() {
    int n,w[300];
    cin>>n;
    for (int i=0;i<n;++i) {
        for (int j=0;j<26;++j)
            w[j]=1;
        string s;
        cin>>s;
        int t=s.length(),ans=1;
        char m=s[0];
        if (t==1)
            w[m-'a']=0;
        for (int j=1;j<t;++j) {
            if (s[j]!=m) {
                if (ans%2==1)
                    w[m-'a']=0;
                ans=1;
                m=s[j];
            }
            else
                ans++;
            if (j==t-1)
                if (ans%2==1)
                    w[m-'a']=0;
        }
        for (int j=0;j<26;++j)
            if (!w[j])
                putchar ('a'+j);
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
using namespace std;
int main() {
    int n,w[300];
    cin>>n;
    for (int i=0;i<n;++i) {
        for (int j=0;j<26;++j)
            w[j]=1;
        string s;
        cin>>s;
        s=' '+s+' ';
        int t=s.length();
        for (int j=1;j<t;++j) {
            if (s[j]!=s[j-1] && s[j]!=s[j+1])
                w[s[j]-'a']=0;
        }
        for (int j=0;j<26;++j)
            if (!w[j])
                putchar ('a'+j);
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#include<string.h>
//int z[200]={0};
using namespace std;
int main()
{
	int i, j, t, len, l2, k, l;
	cin>>t;
	for(i=0; i<t; i++)
	{
		int c=1;
		char s[502];
		cin>>s;
		int z[200]={0};
		len=strlen(s);
		for(j=0; j<len; j++)
		{
			if(s[j]==s[j+1])
			{
				c++;
			}
			else
			{
				if(c%2!=0)
				{
					z[s[j]]++;
					c=1;
				}
			}

		}
		//cout<<s[-1]<<" "<<s[len];
		for(l=97; l<123; l++)
		{
			if(z[l]>=1)
			printf("%c", l);
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#include<string.h>
//int z[200]={0};
using namespace std;
int main()
{
	int i, j, t, len, l2, k, l;
	cin>>t;
	for(i=0; i<t; i++)
	{
		char s[502];
		cin>>s;
		int z[200]={0};
		len=strlen(s);
		for(j=0; j<len; j++)
		{
			if(s[j-1]!=s[j] && s[j]!=s[j+1])
			z[s[j]]++;
		}
		//cout<<s[-1]<<" "<<s[len];
		for(l=97; l<123; l++)
		{
			if(z[l]>=1)
			printf("%c", l);
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int operation()
{
	string s;
	cin >> s;

	bool alphabet[26];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	int count = 0;

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

void operation()
{
	string s;
	cin >> s;

	bool alphabet[26];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	int count = 0;

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int operation()
{
	string s;
	cin >> s;

	bool alphabet[26];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(i == s.size() - 1)
		{
			if(s[i] == s[i-1])
				alphabet[s[i]] = false;
			else
			alphabet[s[i]] = true;
			break;
		}

		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
}


#include<bits/stdc++.h>
using namespace std;
void operation()
{
	string s;
	cin >> s;

	int alphabet[26];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = 0;

	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = 1;
	}

	int count = 0;

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
void operation()
{
	string s;
	cin >> s;

	bool alphabet[26];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	int count = 0;

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int operation()
{
	string s;
	cin >> s;

	int alphabet[26];
	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = 0;

	for(int i = 0; i < s.size(); i++)
	alphabet[s[i]]++;

	for(char c = 'a'; c <= 'z'; c++)
	{
		if(alphabet[c] == 0 || alphabet[c] % 2 == 0)
		continue;
		else
		cout << c;
	}
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
}


#include<bits/stdc++.h>
using namespace std;
int operation()
{
	string s;
	cin >> s;

	bool alphabet[26];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	int count = 0;

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
}


#include<bits/stdc++.h>
using namespace std;
void operation()
{
	string s;
	cin >> s;

	bool alphabet[100000];

	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	int count = 0;

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int operation()
{
	string s;
	cin >> s;

	bool alphabet[26];
	for(char c = 'a'; c <= 'z'; c++)
	alphabet[c] = false;

	for(int i = 0; i < s.size(); i++)
	{
		if(i == s.size() - 1)
		{
			if(s[i] == s[i-1])
				alphabet[s[i]] = false;
			else
			alphabet[s[i]] = true;
			break;
		}

		if(s[i] == s[i+1])
			i++;
		else
		alphabet[s[i]] = true;
	}

	for(char c = 'a'; c <= 'z'; c++)
	if(alphabet[c])
	cout << c;
	cout << endl;
}
int main()
{
	int q;
	cin >> q;
	while(q--)
	operation();
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,len,j;
    string s;

    cin>>t;

    for(i=0;i<t;i++)
    {
        cin>>s;

        map<char,int> alpha;
        set<char> pri;
        set<char>::iterator it1;
        map<char,int>::iterator it;

        len=s.length();

        for(j=0;j<len;j++)
            alpha[s[j]]++;

        for(it=alpha.begin();it!=alpha.end();it++)
        {
            if(it->second%2!=0)
                pri.insert(it->first);
        }
        for(it1=pri.begin();it1!=pri.end();it1++)
            cout<<*it1;
        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,len,j;
    string s;

    cin>>t;

    for(i=0;i<t;i++)
    {
        cin>>s;

        set<char> pri;
        set<char>::iterator it;

        len=s.length();

        for(j=0;j<len-1;j++)
        {
            if(s[j]!=s[j+1])
            {
                pri.insert(s[j]);
            }
            else
                j++;
        }
        if(s[len-1]!=s[len-2])
            pri.insert(s[len-1]);

        for(it=pri.begin();it!=pri.end();it++)
            cout<<*it;
        cout<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    String S;
    int t,i,j;
    cin>>t;
    for(i=0;i<t;i++)
    {
        j=0
        cin>>S;
        while(j<S.length())
        {
            if(S[j]==S[j+1])
                j+=2;
            else
            {
                j+=1;
                cout<<S[j];
            }
        }
    }
}


#include<iostream>
using namespace std;
#include<string.h>

int main()
{
    int t,i,j,l;
    char *a;
    cin>>t;
    for(i=0;i<t;i++)
    {
        a=new char[100];
        cin>>a;
        l=strlen(a);
        j=0;

        while(j<l-1)
        {
            if(*(a+j)==*(a+j+1))
                j+=2;
            else
            {
                j+=1;
                cout<<*(a+j);
            }
        }
        if(*(a+l-1)!=*(a+l-2))
            cout<<*(a+l-1);

        cout<<"\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int t,i,len,j;
    string s;

    cin>>t;

    for(i=0;i<t;i++)
    {
        cin>>s;

        map<char,int> alpha;
        set<char> pri;
        set<char>::iterator it;

        len=s.length();

        for(j=0;j<len;j++)
            alpha[s[j]]++;

        for(j=0;j<len-1;j++)
        {
            if(s[j]!=s[j+1])
            {
                pri.insert(s[j]);
            }
            else
                j++;
        }
        if(s[len-1]!=s[len-2] || (s[len-1]==s[len-2] && alpha[s[len-1]]%2!=0 ))
            pri.insert(s[len-1]);

        for(it=pri.begin();it!=pri.end();it++)
            cout<<*it;

        cout<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
#include<string.h>

int main()
{
    int t,i,j,l;
    char *a;
    cin>>t;
    for(i=0;i<t;i++)
    {
        a=new char[100];
        cin>>a;
        l=strlen(a);
        j=0;

        while(j<l-1)
        {
            if(a[j]==a[j+1])
                j+=2;
            else
            {
                j+=1;
                cout<<a[j];
            }
        }
        if(a[l-1]!=a[l-2])
            cout<<a[l-1];
    }

    return 0;
}


#include<iostream>
using namespace std;
#include<string.h>

int main()
{
    int t,i,j,l;
    char *a;
    cin>>t;
    for(i=0;i<t;i++)
    {
        a=new char[100];
        cin>>a;
        l=strlen(a);
        j=0;

        while(j<l-1)
        {
            if(a[j]==a[j+1])
                j+=2;
            else
            {
                j+=1;
                cout<<a[j]<<"\n";
            }
        }
        if(a[l-1]!=a[l-2])
            cout<<a[l-1]<<"\n";
    }

    return 0;
}


#include<iostream>
using namespace std;
#include<string.h>

int main()
{
    int t,i,j,l;
    char *a;
    cin>>t;
    for(i=0;i<t;i++)
    {
        a=new char[100];
        cin>>a;
        l=strlen(a);
        j=0;

        while(j<l-1)
        {
            if(*(a+j)==*(a+j+1))
                j+=2;
            else
            {

                cout<<*(a+j);
                j+=1;
            }
        }
        if(*(a+l-1)!=*(a+l-2))
            cout<<*(a+l-1);

        cout<<"\n";
    }

    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{   char arr2[1000000],temp;string arr;
long long i,j,p=0,n,test;
//cout<<"enter the test cases";
cin>>test;
  while(test>0)
  {  for(i=0;i<1000000;i++)
    arr2[i]=-1;
  	test=test-1;
    p=0;
//	cout<<"enter the string";
	cin>>arr;
	//cout<<arr;
	n=arr.size();
	for(i=0;i<n;i++)
{   if(i==n-1)
	{ //  cout<<arr[i];
		arr2[p]=arr[i];
		p=p+1;
	}

   else if(arr[i]==arr[i+1])
	i=i+1;
	else if(arr[i]!=arr[i+1]){
	    arr2[p]=arr[i];
		p=p+1;

	}

}
for(i=0;i<p-1;i++)
{
	if(arr2[i]>arr2[i+1])
{
		temp=arr2[i];
	arr2[i]=arr2[i+1];
	arr2[i+1]=temp;
	}
}
for(i=0;i<p;i++)
{  for(j=i+1;j<p;j++)
{
		if(arr2[i]==arr2[j])
		arr2[j]=-1;
}

}
for(i=0;i<p;i++)
{
	if(arr2[i]!=-1)
	cout<<arr2[i];

}
cout<<"\n";
}
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{   char arr2[1000000],temp;string arr;
long long i,j,p=0,n,test;
//cout<<"enter the test cases";
cin>>test;
  while(test>0)
  {  for(i=0;i<1000000;i++)
    arr2[i]=-1;
  	test=test-1;
    p=0;
//	cout<<"enter the string";
	cin>>arr;
	//cout<<arr;
	n=arr.size();
	for(i=0;i<n;i++)
{   if(i==n-1)
	{ //  cout<<arr[i];
		arr2[p]=arr[i];
		p=p+1;
	}

   else if(arr[i]==arr[i+1])
	i=i+1;
	else if(arr[i]!=arr[i+1]){
	    arr2[p]=arr[i];
		p=p+1;

	}

}
for(i=0;i<p-1;i++)
{  for(j=i+1;j<n;j++)
{
	if(arr2[i]>arr2[j])
{
		temp=arr2[i];
	arr2[i]=arr2[j];
	arr2[j]=temp;
	}
}
}
for(i=0;i<p;i++)
{  for(j=i+1;j<p;j++)
{
		if(arr2[i]==arr2[j])
		arr2[j]=-1;
}

}
for(i=0;i<p;i++)
{
	if(arr2[i]!=-1)
	cout<<arr2[i];

}
cout<<"\n";
}
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{   char arr2[1000],temp;string arr;
long long i,j,p=0,n,test;
//cout<<"enter the test cases";
cin>>test;
  while(test>0)
  {  for(i=0;i<1000;i++)
    arr2[i]=-1;
  	test=test-1;

//	cout<<"enter the string";
	cin>>arr;
	//cout<<arr;
	n=arr.size();
	for(i=0;i<n;i++)
{   if(i==n-1)
	{ //  cout<<arr[i];
		arr2[p]=arr[i];
		p=p+1;
	}

   else if(arr[i]==arr[i+1])
	i=i+1;
	else if(arr[i]!=arr[i+1]){
	    arr2[p]=arr[i];
		p=p+1;

	}

}
for(i=0;i<p-1;i++)
{
	if(arr2[i]>arr2[i+1])
{
		temp=arr2[i];
	arr2[i]=arr2[i+1];
	arr2[i+1]=temp;
	}
}
for(i=0;i<p;i++)
{  for(j=i+1;j<p;j++)
{
		if(arr2[i]==arr2[j])
		arr2[j]=-1;
}

}
for(i=0;i<p;i++)
{
	if(arr2[i]!=-1)
	cout<<arr2[i];
	cout<<"\n";
}
}
}


#include<cstdio>
const int MAXN = 3e2 + 5;
const int MAXM = 1e6 + 5;
const int MAXD = 1e3 + 5;

int d[MAXN];
int g[MAXD][MAXD];

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

	int tot=d[n]+1;
	for(int k=1; k<n; ++k)
	{
		for(int i=1; i<=d[k]; ++i)
			for(int j=1; j<i; ++j)
				g[i][j]=g[j][i]=1;

		for(int i=1; i<=d[k]; ++i)
			for(int j=d[k]+1; j<=tot-k+1; ++j)
				g[i][j]=g[j][i]=1;
	}

	int m=0;
	for(int i=1; i<=tot; ++i)
		for(int j=1; j<i; ++j)
			if(g[i][j]) ++m;
	printf("%d\n",m);
	for(int i=1; i<=tot; ++i)
		for(int j=1; j<i; ++j)
			if(g[i][j]) printf("%d %d\n",i,j);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int d[305],deg[1005];
vector<pair<int,int> > vec;
int main()
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>d[i];
    int l=1,r=n,q=d[n]+1,lst=0;
    for(int i=1;i<=q;i++)
	{
        if(l<=r && q-i+deg[i]==d[r])
		{
            lst=1;
            r--;
        }
        else if(l<=r && deg[i]==d[l])
		{
            lst=0;
            l++;
        }
        else if(l<=r) printf("OMO\n");
        if(lst)
		{
            for(int j=i+1;j<=q;j++)
			{
                deg[i]++;
				deg[j]++;
                vec.push_back(make_pair(i,j));
            }
        }
    }
    cout<<vec.size()<<endl;
    for(int i=0;i<vec.size();i++)
        printf("%d %d\n", vec[i].first, vec[i].second);
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 3e2 + 5;
const int MAXD = 1e3 + 5;

int d[MAXN];
int g[MAXD][MAXD],deg[MAXD];

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

	reverse(d+1,d+n+1);
	int m=d[1]+1;
	for(int i=1; i<=m; ++i)
		for(int j=1; j<i; ++j)
			g[i][j]=g[j][i]=1;
	for(int i=1; i<=m; ++i) deg[i]=d[1];

	for(int k=1; k<=n; ++k)
	{
		for(int i=k; i<=m; ++i)
			for(int j=i+1; j<=m && deg[i]>d[k]; ++j)
				if(g[i][j] && deg[j]>d[k])
				{
					g[i][j]=g[j][i]=0;
					--deg[i]; --deg[j];
				}
	}

	int ans=0;
	for(int i=1; i<=m; ++i)
		for(int j=i+1; j<=m; ++j)
			if(g[i][j]) ++ans;

	printf("%d\n",ans);
	for(int i=1; i<=m; ++i)
		for(int j=i+1; j<=m; ++j)
			if(g[i][j]) printf("%d %d\n",i,j);
	//for(int i=1; i<=m; ++i) printf("%d: %d\n",i,deg[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int d[305],deg[1005];
vector<pair<int,int> > vec;
int main()
{
	int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>d[i];
    int l=1,r=n,q=d[n]+1,lst=0;
    for(int i=1;i<=q;i++)
	{
        if(l<=r && q-i+deg[i]==d[r])
		{
            lst=1;
            r--;
        }
        else if(l<=r && deg[i]==d[l])
		{
            lst=0;
            l++;
        }
        else printf("OMO\n");
        if(lst)
		{
            for(int j=i+1;j<=q;j++)
			{
                deg[i]++;
				deg[j]++;
                vec.push_back(make_pair(i,j));
            }
        }
    }
    cout<<vec.size()<<endl;
    for(int i=0;i<vec.size();i++)
        printf("%d %d\n", vec[i].first, vec[i].second);
    return 0;
}


#include<cstdio>
const int MAXN = 3e2 + 5;
const int MAXM = 1e6 + 5;
const int MAXD = 1e3 + 5;

int d[MAXN];
int g[MAXD][MAXD];

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

	int tot=d[n]+1;
	for(int k=1; ; ++k)
	{
		int l=k, r=n-k+1;
		if(l>r) break;
		for(int i=d[l-1]+1; i<=d[l]; ++i)
			for(int j=d[l-1]+1; j<i; ++j)
				g[i][j]=g[j][i]=1;

		for(int i=d[l-1]+1; i<=d[l]; ++i)
			for(int j=d[l]+1; j<=d[r]+1; ++j)
				g[i][j]=g[j][i]=1;
	}

	int m=0;
	for(int i=1; i<=tot; ++i)
		for(int j=1; j<i; ++j)
			if(g[i][j]) ++m;
	printf("%d\n",m);
	for(int i=1; i<=tot; ++i)
		for(int j=1; j<i; ++j)
			if(g[i][j]) printf("%d %d\n",i,j);
	return 0;
}


#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <deque>
#include <set>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#endif
#include <ctime>
#include <queue>
#include <stack>
#include<iomanip>
#include <sstream>
#include <cmath>
//#include "utils/haha.h"
//#include "utils/max_flow.h"
using namespace std;
typedef pair<int, int> PII;
typedef pair<string, string> PSS;
typedef pair<string, int> PSI;
typedef pair<int, PII> PIP;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef pair<double, double> PDD;
typedef pair<ll, PII> PLP;
#define CLS(x, v) (memset((x), (v), sizeof((x))))
const double pi = acos(-1);
const int mod = 1000000007;
const int inf = 0x3fffffff;
const string imp = "IMPOSSIBLE";
const ll long_inf = 1LL<<60;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a; }

int sgn(int x) {return x == 0 ? 0 : (x > 0 ? 1 : -1);}

const int N = 1000010;
int cnt;
int x[N], y[N];

void calc(vector<int> d) {
    if (d.size() == 0) return;
    if (d.size() == 1) {
        // 1 ... d+1 clique
        for(int i = 1; i <= d.back() + 1; i++) {
            for(int j = i + 1; j <= d.back() + 1; j++) {
                x[cnt] = i;
                y[cnt] = j;
                cnt++;
            }
        }
        return;
    }
    vector<int> nd;
    for(int i = 1; i < d.size() - 1; i++) {
        nd.push_back(d[i] - d[0]);
    }
    int partA = nd.size() ? nd.back() + 1 : 1;
    // 1..partA
    // dk - dk-1 : partA + 1 ~ partA + partB
    // d[0]: partA + partB + 1 ~ partA + partB + partC
    int partB = d[d.size() - 1] - d[d.size() - 2];
    int partC = d[0];

    // edge inside partA
    calc(nd);

    // edge between partA and partC
    for(int i = 1; i <= partA; i++) {
        for(int j = 1; j <= partC; j++) {
            x[cnt] = i;
            y[cnt] = partA + partB + j;
            cnt++;
        }
    }

    // edge between partB and PartC
    for(int i = 1; i <= partB; i++) {
        for(int j = 1; j <= partC; j++) {
            x[cnt] = partA + i;
            y[cnt] = partA + partB + j;
            cnt++;
        }
    }

    // edge inside partC
    for(int i = 1; i <= partC; i++) {
        for(int j = i + 1; j <= partC; j++) {
            x[cnt] = partA + partB + i;
            y[cnt] = partA + partB + j;
            cnt++;
        }
    }
}

void solve(int ncase) {
    //cout << "Case #" << ncase << ": ";
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) {
        cin >> d[i];
    }
    calc(d);

    printf("%d\n", cnt);
    for(int i = 0; i < cnt; i++) {
        printf("%d %d\n", x[i], y[i]);
    }
}

int main() {
    ios::sync_with_stdio(false);
    //cout << std::fixed;
    //cout << setprecision(16);
#ifdef _zzz_
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    //precalc();
    int T = 1;
    //scanf("%d", &T);
    //cin >> T;
    int ncase = 0;
    while(T --) {
        solve(++ ncase);
        //test();
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
typedef unsigned long long UL;
typedef pair<int,int> II;
typedef vector<II> VII;

void get_edges(const int i_offset, const int d_offset, const int from_index, const int to_index,
               const vector<int>& D, VII& edges) {
    int first_index = i_offset;
    int last_index = first_index + D[to_index]-d_offset;

    for(int i=0, k=last_index; i<D[from_index]-d_offset; ++i, --k) {
        for(int j=first_index; j<k; ++j) {
            edges.push_back(II(k, j));
        }
    }
    if (to_index - from_index > 1) {
        get_edges(i_offset + D[to_index] - D[to_index - 1], D[from_index],
                  from_index + 1, to_index - 1, D, edges);
    }
}

struct Node {
    vector<int> adj;
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    vector<int> D(N);
    for(int i=0; i<N; ++i) {
        cin >> D[i];
    }

    VII res;
    res.reserve(D.back()*(D.back()+1)/2);
    get_edges(1, 0, 0, D.size()-1, D, res);

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
typedef unsigned long long UL;
typedef pair<int,int> II;
typedef vector<II> VII;

void get_edges(const int i_offset, const int d_offset, const int from_index, const int to_index,
               const vector<int>& D, VII& edges) {
    int first_index = i_offset;
    int last_index = first_index + D[to_index]-d_offset;

    for(int i=0, k=last_index; i<D[from_index]-d_offset; ++i, --k) {
        for(int j=first_index; j<k; ++j) {
            edges.push_back(II(k, j));
        }
    }
    if (to_index - from_index > 1) {
        get_edges(i_offset + D[to_index] - D[to_index - 1], D[from_index],
                  from_index + 1, to_index - 1, D, edges);
    }
}

struct Node {
    vector<int> adj;
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    vector<int> D(N);
    for(int i=0; i<N; ++i) {
        cin >> D[i];
    }

    VII res;
    res.reserve(D.back()*(D.back()+1)/2);
    get_edges(1, 0, 0, D.size()-1, D, res);

    cout << res.size() << endl;
    for(int i=0; i<res.size(); ++i) {
        cout << res[i].first << " " << res[i].second << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int UI;
typedef unsigned long long UL;
typedef pair<int,int> II;
typedef vector<II> VII;

void get_edges(const int i_offset, const int d_offset, const int from_index, const int to_index,
               const vector<int>& D, VII& edges) {
    int first_index = i_offset;
    int last_index = first_index + D[to_index]-d_offset;
/*    int span = D[from_index]-d_offset;
    if (from_index - to_index > 1) {

        int alt_span =
    }

    int span2 = */

    for(int i=0, k=last_index; i<D[from_index]-d_offset; ++i, --k) {
        for(int j=first_index; j<k; ++j) {
            edges.push_back(II(k, j));
        }
    }
    if (to_index - from_index > 1) {
        get_edges(i_offset + D[to_index] - D[to_index - 1], D[from_index],
                  from_index + 1, to_index - 1, D, edges);
    }
}

struct Node {
    vector<int> adj;
};

bool validate(const vector<int>& D, const VII& E) {
    const int N = D.back()+1;
    vector<Node> nodes(N);
    for(int i=0; i<E.size(); ++i) {
        int u = E[i].first;
        int v = E[i].second;
        --u; --v;
        nodes[u].adj.push_back(v);
        nodes[v].adj.push_back(u);
    }
    set<int> degrees;
    for(int i=0; i<N; ++i) {
        degrees.insert(nodes[i].adj.size());
    }
    if (degrees.size() != D.size()) {
        return false;
    }
    int i = 0;
    for(auto it = degrees.begin(); i<D.size(); ++it, ++i) {
        if (*it != D[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    vector<int> D(N);
    for(int i=0; i<N; ++i) {
        cin >> D[i];
    }

    VII res;
    get_edges(1, 0, 0, D.size()-1, D, res);

    bool valid = validate(D, res);
    if (!valid) {
        abort();
    }

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector<int> a;
int b[2000];
vector<pair<int,int> > ans;

int main() {
	int n;
	cin >> n;
	int sum = 0, maxx = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		maxx = max(maxx,x);
		a.push_back(x);
		sum += x;
	}
	int fodd = -1, feven = -1;
	for (int i = 0; i < n; i++) if (a[i] & 1) { fodd = i; break;}
	for (int i = 0; i < n; i++) if (!(a[i] & 1)) { feven = i; break;}
	if (sum & 1) {
		for (int i = n; i < maxx; i++) a.push_back(a[feven]);
		a.push_back(a[fodd]);
	}
	else
		for (int i = n; i <= maxx; i++) a.push_back(a[feven]);
	sort(a.begin(),a.end());
	//for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
	for (int i = a.size()-1; i >= 0; i--) if (b[i] < a[i]) {
		for (int j = i-1; b[i] < a[i] && j >= 0; j--) if (b[j] < a[j]) {
			ans.push_back({j+1,i+1});
			b[i]++;
			b[j]++;
		}
	}
	cout << ans.size() << "\n";
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int> > ans;
int np = 0, d[500];

void solve(int l, int r) {
	if (l > r) {
		np++;
	}
	else if (l == r) {
		np += d[r] + 1;
		for (int i = 1; i < np; i++)
			for (int j = i+1; j <= np; j++)
				ans.push_back({i,j});
	}
	else if (l < r) {
		d[r] -= d[r-1];
		for (int i = l+1; i < r; i++) d[i] -= d[l];
		solve(l+1,r-1);
		np += d[r] + d[l];
		for (int i = np-d[l]+1; i <= np; i++)
			for (int j = 1; j < i; j++)
				ans.push_back({i,j});
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> d[i];
	solve(0,n-1);
	cout << ans.size() << "\n";
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << "\n";
}


#include <bits/stdc++.h>
using namespace std;

vector<pair<int,int> > ans;
int np = 0, d[500];

void solve(int l, int r) {
	if (l > r) {
		np++;
		return;
	}
	if (l == r) {
		np += d[r] + 1;
		for (int i = 1; i < np; i++)
			for (int j = i+1; j <= np; j++)
				ans.push_back({i,j});
	}
	if (l < r) {
		d[r] -= d[r-1];
		for (int i = l+1; i < r; i++) d[i] -= d[l];
		solve(l+1,r-1);
		np += d[r] + d[l];
		for (int i = np; i > np-d[l]; i--)
			for (int j = 1; j <= np-d[l]; j++)
				ans.push_back({i,j});
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> d[i];
	solve(0,n-1);
	cout << ans.size() << "\n";
	for (int i = 0; i < ans.size(); i++)
		cout << ans[i].first << " " << ans[i].second << "\n";
}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000000 + 100;
int f[maxn];
int a[maxn];
int x[maxn], y[maxn];

int n;
int l = 0, r = 0, cnt = 0;

int main()
{
    //freopen("DATA.c", "r", stdin);
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){scanf("%d",&a[i]); f[a[i]] = 1;}
    while(a[n] >= r){
        do{
            for(int i = l + 2; i <= a[n] + 1; i ++){
                x[cnt] = l+1; y[cnt] = i; cnt ++;
            }
            l ++; r ++;
        }while(!f[r]);
        n--;
    }
    printf("%d\n", cnt);
    for(int i = 0; i < cnt; i ++){
        printf("%d %d\n", x[i], y[i]);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;

const int maxn = 1000 + 10;
int g[maxn][maxn];
int d[maxn]; //节点i的度数
int a[maxn];
int cnt[maxn];
int node;
set<int> s;
int n;
int edge;

void link(int x, int y)
{
    g[x][y] = 1;
    g[y][x] = 1;
    d[x] ++;
    d[y] ++;
    cnt[d[x]]++;
    cnt[d[y]]++;
    edge ++;
    //cout<<"link "<<x<<" "<<y<<endl;
}

int main()
{
    freopen("DATA.c", "r", stdin);
    cin>>n;
    edge = 0;
    memset(g,0,sizeof(g));
    memset(d,0,sizeof(d));
    memset(a,0,sizeof(a));
    memset(cnt,0,sizeof(cnt));
    for(int i = 1; i <= n; i ++){
        cin>>a[i];
        s.insert(a[i]);
    }
    node = a[n] + 1;
    int op = node;
    int c = 0;
    for(int i = n; i >= 1; i --){
        int k = node - 1;
        for(int j = 0; j < a[i] - c; j ++){
            link(node,k); k--;
        }
        node--;
        c++;
    }
    node = a[n] + 1;
     //for(int i = 1; i <= node; i ++) cout<<d[i]<<" "; cout<<endl;
    for(int i = 1; i <= node; i ++){
        while(!s.count(d[i])){
            //cout<<"d[i] "<<d[i]<<endl;
            for(int j = i + 1; j <= node; j ++){
                if(s.count(d[j]) && cnt[d[j]] > 1 && g[i][j] == 0){
                    link(i,j); break;
                }
                if(!s.count(d[j]) && g[i][j] == 0){
                    link(i,j); break;
                }
            }
        }
    }
    node = a[n] + 1;
    cout<<edge<<endl;
    for(int i = 1; i <= node; i ++){
        for(int j = i + 1; j <= node; j ++){
            if(g[i][j]) cout<<i<<" "<<j<<endl;
        }
    }
    //for(int i = 1; i <= node; i ++) cout<<d[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int maxn = 1000 + 100;
int f[maxn];
int a[maxn];
int x[maxn], y[maxn];

int n;
int l = 0, r = 0, cnt = 0;

int main()
{
    //freopen("DATA.c", "r", stdin);
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++){scanf("%d",&a[i]); f[a[i]] = 1;}
    while(a[n] >= r){
        do{
            for(int i = l + 2; i <= a[n] + 1; i ++){
                x[cnt] = l+1; y[cnt] = i; cnt ++;
            }
            l ++; r ++;
        }while(!f[r]);
        n--;
    }
    printf("%d\n", cnt);
    for(int i = 0; i < cnt; i ++){
        printf("%d %d\n", x[i], y[i]);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;

const int maxn = 1000 + 10;
int g[maxn][maxn];
int d[maxn]; //节点i的度数
int a[maxn];
int cnt[maxn];
int node;
int s[maxn];
int n;
int edge;

void link(int x, int y)
{
    g[x][y] = 1;
    g[y][x] = 1;
    d[x] ++;
    d[y] ++;
    cnt[d[x]]++;
    cnt[d[y]]++;
    edge ++;
    //cout<<"link "<<x<<" "<<y<<endl;
}

int main()
{
    //freopen("DATA.c", "r", stdin);
    //cin>>n;
    scanf("%d", &n);
    edge = 0;
    for(int i = 1; i <= n; i ++){
        scanf("%d", &a[i]);
        s[a[i]] = 1;
    }
    node = a[n] + 1;
    int op = node;
    int c = 0;
    for(int i = n; i >= 1; i --){
        int k = node - 1;
        for(int j = 0; j < a[i] - c; j ++){
            link(node,k); k--;
        }
        node--;
        c++;
    }
    node = a[n] + 1;
     //for(int i = 1; i <= node; i ++) cout<<d[i]<<" "; cout<<endl;
    for(int i = 1; i <= node; i ++){
        while(!s[d[i]]){
            //cout<<"d[i] "<<d[i]<<endl;
            for(int j = i + 1; j <= node; j ++){
                if(s[d[j]] && cnt[d[j]] > 1 && g[i][j] == 0){
                    link(i,j); break;
                }
                if(!s[d[j]] && g[i][j] == 0){
                    link(i,j); break;
                }
            }
        }
    }
    node = a[n] + 1;
    //cout<<edge<<endl;
    printf("%d\n", edge);
    for(int i = 1; i <= node; i ++){
        for(int j = i + 1; j <= node; j ++){
            if(g[i][j]) //cout<<i<<" "<<j<<endl;
                printf("%d %d\n", i, j);
        }
    }
    //for(int i = 1; i <= node; i ++) cout<<d[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const  int maxn = 1000 + 10;
int a[maxn];
vector<pair<int,int> > ans;
int n;

int main()
{
    //freopen("DATA.c", "r", stdin);
    cin>>n;
    for(int i = 1; i <= n; i ++) cin>>a[i];
    int l = 1, r = n, st = 1, ends = a[n] + 1;
    while(l <= r){
        for(int i = 1; i <= a[l] - a[l-1]; i ++){
            for(int j = st+1; j <= ends; j ++){
                ans.push_back(make_pair(st,j));
            }
            st ++;
        }
        l++;
        ends = a[--r] + 1;
    }
    cout<<ans.size()<<endl;
    for(int i = 0; i < ans.size(); i ++){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;

const int maxn = 1000 + 10;
int g[maxn][maxn];
int d[maxn]; //节点i的度数
int a[maxn];
int cnt[maxn];
int node;
int s[maxn];
int n;
int edge;

void link(int x, int y)
{
    g[x][y] = 1;
    g[y][x] = 1;
    d[x] ++;
    d[y] ++;
    cnt[d[x]]++;
    cnt[d[y]]++;
    edge ++;
    //cout<<"link "<<x<<" "<<y<<endl;
}

int main()
{
    //freopen("DATA.c", "r", stdin);
    //cin>>n;
    scanf("%d", &n);
    edge = 0;
    for(int i = 1; i <= n; i ++){
        scanf("%d", &a[i]);
        s[a[i]] = 1;
    }
    node = a[n] + 1;
    int op = node;
    int c = 0;
    for(int i = n; i >= 1; i --){
        int k = node - 1;
        for(int j = 0; j < a[i] - c; j ++){
            link(node,k); k--;
        }
        node--;
        c++;
    }
    node = a[n] + 1;
     //for(int i = 1; i <= node; i ++) cout<<d[i]<<" "; cout<<endl;
    for(int i = 1; i <= node; i ++){
        if(s[d[i]] && d[i] >= a[0]) break;
        while(!s[d[i]]){
            //cout<<"d[i] "<<d[i]<<endl;
            for(int j = i + 1; j <= node; j ++){
                if(s[d[j]] && cnt[d[j]] > 1 && g[i][j] == 0){
                    link(i,j); break;
                }
                if(!s[d[j]] && g[i][j] == 0){
                    link(i,j); break;
                }
            }
        }
    }
    node = a[n] + 1;
    //cout<<edge<<endl;
    printf("%d\n", edge);
    for(int i = 1; i <= node; i ++){
        for(int j = i + 1; j <= node; j ++){
            if(g[i][j]) //cout<<i<<" "<<j<<endl;
                printf("%d %d\n", i, j);
        }
    }
    //for(int i = 1; i <= node; i ++) cout<<d[i]<<" ";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;

const int maxn = 1000 + 10;
int g[maxn][maxn];
int d[maxn]; //节点i的度数
int a[maxn];
int cnt[maxn];
int node;
int s[maxn];
int n;
int edge;

void link(int x, int y)
{
    g[x][y] = 1;
    g[y][x] = 1;
    d[x] ++;
    d[y] ++;
    cnt[d[x]]++;
    cnt[d[y]]++;
    edge ++;
    //cout<<"link "<<x<<" "<<y<<endl;
}

int main()
{
    //freopen("DATA.c", "r", stdin);
    cin>>n;
    edge = 0;
    memset(g,0,sizeof(g));
    memset(d,0,sizeof(d));
    memset(a,0,sizeof(a));
    memset(cnt,0,sizeof(cnt));
    for(int i = 1; i <= n; i ++){
        scanf("%d", &a[i]);
        s[a[i]] = 1;
    }
    node = a[n] + 1;
    int op = node;
    int c = 0;
    for(int i = n; i >= 1; i --){
        int k = node - 1;
        for(int j = 0; j < a[i] - c; j ++){
            link(node,k); k--;
        }
        node--;
        c++;
    }
    node = a[n] + 1;
     //for(int i = 1; i <= node; i ++) cout<<d[i]<<" "; cout<<endl;
    for(int i = 1; i <= node; i ++){
        while(!s[d[i]]){
            //cout<<"d[i] "<<d[i]<<endl;
            for(int j = i + 1; j <= node; j ++){
                if(s[d[j]] && cnt[d[j]] > 1 && g[i][j] == 0){
                    link(i,j); break;
                }
                if(!s[d[j]] && g[i][j] == 0){
                    link(i,j); break;
                }
            }
        }
    }
    node = a[n] + 1;
    cout<<edge<<endl;
    for(int i = 1; i <= node; i ++){
        for(int j = i + 1; j <= node; j ++){
            if(g[i][j]) //cout<<i<<" "<<j<<endl;
                printf("%d %d\n", i, j);
        }
    }
    //for(int i = 1; i <= node; i ++) cout<<d[i]<<" ";
    return 0;
}