#include <iostream>
#include <string>

using namespace std;

int main() {
    int t, temp;
    cin >> t;
    string s, a, d;
    getline(cin, s);
    for (int i = 0; i < t; i++) {
        getline(cin, s);
        for (int j = 0; j < s.size(); j++) {
            if (j == 0 && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
            if (s.size() - 1 != 0 && j == s.size() - 1 && s[j] != s[j - 1]) {
                a.push_back(s[j]);
            }
            if (j != 0 && j != s.size() - 1 && s[j] != s[j - 1] && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
        }
        if (i != t - 1) {
            a.push_back(' ');
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            for (int j = 0; j < a.size(); j++) {
                if (a[i] == ' ') {
                    break;
                }
                if (i != 0 && a[i - 1] != ' ' && temp > a[i]) {
                    int tenp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tenp;
                }
                temp = a[i];
            }
        }
    }
    for (int i = 0; i < a.size(); i++)  {
        if (a[i] != ' ') {
            d.push_back(a[i]);
        } else {
            cout << d;
            cout << endl;
            d.clear();
        }
        if (i == a.size() - 1) {
            cout << d;
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t, temp;
    cin >> t;
    string s, a;
    getline(cin, s);
    for (int i = 0; i < t; i++) {
        getline(cin, s);
        for (int j = 0; j < s.size(); j++) {
            if (j == 0 && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
            if (j == s.size() - 1 && s[j] != s[j - 1]) {
                a.push_back(s[j]);
            }
            if (j != 0 && j != s.size() - 1 && s[j] != s[j - 1] && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
        }
        if (i != t - 1) {
            a.push_back(' ');
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            for (int j = 0; j < a.size(); j++) {
                if (a[i] == ' ') {
                    break;
                }
                if (i != 0 && a[i - 1] != ' ' && temp > a[i]) {
                    int tenp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tenp;
                }
                temp = a[i];
            }
        }
    }
    for (int i = 0; i < a.size(); i++)  {
        if (a[i] != ' ') {
            cout << a[i];
        } else {
            cout << endl;
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t, temp, tebp;
    cin >> t;
    string s, a, d;
    getline(cin, s);
    for (int i = 0; i < t; i++) {
        getline(cin, s);
        for (int j = 0; j < s.size(); j++) {
            if (j == 0 && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
            if (s.size() - 1 != 0 && j == s.size() - 1 && s[j] != s[j - 1]) {
                a.push_back(s[j]);
            }
            if (j != 0 && j != s.size() - 1 && s[j] != s[j - 1] && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
        }
        if (i != t - 1) {
            a.push_back(' ');
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            for (int j = 0; j < a.size(); j++) {
                if (i != 0 && a[i - 1] != ' ' && a[i] != ' ' && temp > a[i]) {
                    int tenp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tenp;
                }
                if (a[i] != 0) {
                    temp = a[i];
                }
            }
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            if (i != 0 && tebp < a[i]) {
                d.push_back(tebp);
                if (i == a.size() - 1) {
                    d.push_back(a[i]);
                }
            }
            tebp = a[i];
        } else if (i != a.size() - 1) {
            d.push_back(' ');
        }
    }
    for (int i = 0; i < d.size(); i++)  {
        if (d[i] != ' ') {
            cout << d[i];
        } else {
            cout << endl;
        }
    }
}


#include <iostream>
#include <string>

using namespace std;

int main() {
    int t, temp;
    cin >> t;
    string s, a;
    getline(cin, s);
    for (int i = 0; i < t; i++) {
        getline(cin, s);
        for (int j = 0; j < s.size(); j++) {
            if (j == 0 && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
            if (s.size() - 1 != 0 && j == s.size() - 1 && s[j] != s[j - 1]) {
                a.push_back(s[j]);
            }
            if (j != 0 && j != s.size() - 1 && s[j] != s[j - 1] && s[j] != s[j + 1]) {
                a.push_back(s[j]);
            }
        }
        if (i != t - 1) {
            a.push_back(' ');
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= 'a' && a[i] <= 'z') {
            for (int j = 0; j < a.size(); j++) {
                if (i != 0 && a[i - 1] != ' ' && a[i] != ' ' && temp > a[i]) {
                    int tenp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tenp;
                }
                if (a[i] != 0) {
                    temp = a[i];
                }
            }
        }
    }
    for (int i = 0; i < a.size(); i++)  {
        if (a[i] != ' ') {
            cout << a[i];
        } else {
            cout << endl;
        }
    }
}


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

int main(){
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;
		int seen[26]{0};
		string ans = "";
		int n = s.size();
		for(int i = 0; i < n; i++){
			if(i == n-1){
				seen[s[i]-'a'] = 1;
				continue;
			}
			if(s[i] != s[i+1]){
				seen[s[i]-'a'] = 1;
			}else{
				i++;
			}
		}
		stringstream ss;
		for(int i = 0; i < 26; i++)if(seen[i]){
		    ss << (char)(i+'a');
		}
		cout << ss.str() << "\n";
	}
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back

string removeSpaces(string input)
{
  input.erase(std::remove(input.begin(),input.end(),' '),input.end());
  return input;
}

int main() {
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res;
        cin >> s;
        for(int j = 0; j <= s.length() - 1; j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1])
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                res.insert(0, 1, char(s[j]));
            }
        }
        cout << res << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back
int was[26];
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res;
        cin >> s;
        for(int j = 0; j <= s.length() - 1; j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1] && was[char(s[j])] == 0)
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                if(was[char(s[j])] == 0) {
                    res.insert(0, 1, char(s[j]));
                    was[char(s[j])] = 1;
                }
            }
        }
        sort(res.begin(), res.end());
        cout << res << endl;
        res = "";
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back

int main() {
    //freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res = "";
        cin >> s;
        for(int j = 0; j <= s.length(); j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1])
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                res.insert(0, 1, char(s[j]));
            }

        }
        cout << res << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res;
        cin >> s;
        for(int j = 0; j <= s.length() - 1; j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1])
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                res.insert(0, 1, char(s[j]));
            }
        }
        sort(res.begin(), res.end());
        cout << res << endl;
        res = "";
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back
int was[26];
int main() {
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res;
        cin >> s;
        for(int i = 0; i <= 25; i++) {
            was[i] = 0;
        }
        for(int j = 0; j <= s.length() - 1; j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1] && was[char(s[j]) - 97] == 0)
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                if(was[char(s[j]) - 97] == 0) {
                    res.insert(0, 1, char(s[j]));
                    was[char(s[j]) - 97] = 1;
                }
            }
        }
        sort(res.begin(), res.end());
        cout << res << endl;
        res = "";
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back

int main() {
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res = "";
        cin >> s;
        for(int j = 0; j <= s.length(); j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1])
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                res.insert(0, 1, char(s[j]));
            }

        }
        cout << res << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back

string removeSpaces(string input)
{
  input.erase(std::remove(input.begin(),input.end(),' '),input.end());
  return input;
}

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res;
        cin >> s;
        for(int j = 0; j <= s.length() - 1; j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1])
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                res.insert(0, 1, char(s[j]));
            }
        }
        cout << res << endl;
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back
int was[26];
int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int q;
    cin >> q;
    for(int i = 0; i < q; i++) {
        string s;
        string res;
        cin >> s;
        for(int i = 0; i <= 25; i++) {
            was[i] = 0;
        }
        for(int j = 0; j <= s.length() - 1; j++) {
            if(j == s.length()) {
                if(s[j] != s[j-1] && was[char(s[j]) - 97] == 0)
                    res.insert(0, 1, char(s[j]));
                break;
            }
            if(s[j] == s[j+1]) {
                j++;
            }
            else {
                if(was[char(s[j]) - 97] == 0) {
                    res.insert(0, 1, char(s[j]));
                    was[char(s[j]) - 97] = 1;
                }
            }
        }
        sort(res.begin(), res.end());
        cout << res << endl;
        res = "";
    }
}


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

int main()
{
    string str,str_,ans;
    int n,k=0;
    int index = 0;
    cin>>n;
    while(k<n)
    {
        cin>>str;
        for (int i=0; i<str.size(); i++)
        {
            int j;
            for (j=0; j<i; j++)
                if (str[i] == str[j]) break;
            if (j == i) str_.push_back (str[i]);
        }
        int flag=0,cnt=0;
        for(int i=0;i<str_.size();i++)
        {
            for(int j=0;j<str.size();j++)
            {
                if(str_[i]==str[j]&&str[j]!=str[j+1]&&str[j]!=str[j-1]&&flag==0) ans.push_back(str_[i]),flag++;
                if(str_[i]==str[j])cnt++;
            }
            if(cnt%2!=0&&flag==0) ans.push_back(str_[i]);
            cnt=0;flag=0;
        }
        cout<<ans<<endl;
        k++;
        ans.erase();
        str_.clear();
    }
}


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

using namespace std;

int main() {
  string check,c;
  int flag=1;
  int n,j=0;
  cin>>n;
  vector<pair<char,int>> cnt;
  while(j<n){
    string ans,chk;
    cin>>check;
    chk.insert(0,check);
    sort(check.begin(),check.end());
    for(int i=0;i<check.length();i++)  {
        if(check[i]==check[i+1]) flag++;
        else {
            cnt.push_back(make_pair(check[i],flag));
            flag=1;
        }
    }
    check.clear();
    for(int i=0;i<cnt.size();i++)
      if(cnt[i].second%2!=0) ans.push_back(cnt[i].first);
      else check.push_back(cnt[i].first);
    for(int j=check.size()-1;j>=0;j--){
        for(int i=0;i<chk.size();i++){
            if(check[j]==chk[i]&&chk[i]!=chk[i+1]) {
                if(chk[i]!=chk[i-1]) {
                    ans.push_back(check[j]);
                    check.erase(j,1);
                    }
                }
            }
        }
    cout<<ans<<endl;
    cnt.clear();
    ans.clear();
    j++;
  }
  return 0;
}


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

int main()
{
    string str,str_,ans;
    int n,k=0;
    int index = 0;
    cin>>n;
    while(k<n)
    {
        cin>>str;
        for (int i=0; i<str.size(); i++)
        {
            int j;
            for (j=0; j<i; j++)
                if (str[i] == str[j]) break;
            if (j == i) str_.push_back (str[i]);
        }
        int flag=0,cnt=0;
        for(int i=0;i<str_.size();i++)
        {
            for(int j=0;j<str.size();j++)
            {
                if(str_[i]==str[j]&&str[j]!=str[j+1]&&str[j]!=str[j-1]&&flag==0) ans.push_back(str_[i]),flag++;
                if(str_[i]==str[j])cnt++;
            }
            if(cnt%2!=0&&flag==0) ans.push_back(str_[i]);
            cnt=0;flag=0;
        }
        sort(ans.begin(),ans.end());
        cout<<ans<<endl;
        k++;
        ans.erase();
        str_.clear();
    }
}


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

int main() {
  string check;
  int flag;
  int c,j=0;
  cin>>c;
  while(j<c)
  {
  string ans;
  cin>>check;
  for(int i=0;i<check.length();i++){
    if(check[i]!=check[i+1]) flag=1, ans.push_back(check[i++]);
    else flag=0;
    if(flag)continue;
  }
  cout<<ans;
  }j++;
  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
  string check,c;
  int flag=0;
  int n,j=0;
  cin>>n;
  while(j<n){
    string ans;
    cin>>check;
    sort(check.begin(),check.end());
    for(int i=0;i<check.length();i++)  {
        if(check[i]==check[i+1]) flag++;
        else {
            if(flag%2==0) ans.push_back(check[i]);
            flag=0;
        }
    }
    cout<<ans<<endl;
    j++;
  }
  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main() {
  string check,c;
  int flag=0;
  int n,j=0;
  cin>>n;
  while(j<n){
    string ans;
    cin>>check;
    sort(check.begin(),check.end());
    for(int i=0;i<check.length();i++)  {
        if(check[i]==check[i+1]) flag++;
        else {
            if(flag%2==0) ans.push_back(check[i]);
            flag=0;
        }
    }
    cout<<ans;
    j++;
  }
  return 0;
}


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

int main()
{
    string str,str_,ans;
    int n,k=0;
    int index = 0;
    cin>>n;
    while(k<n)
    {
        cin>>str;
        int cnt=1,j;
        for(j=0;j<str.size();j++)
        {
            if(str[j]==str[j+1]) cnt++;
            else
            {
                if(cnt%2!=0) ans.push_back(str[j]);
                //cout<<"  { "<<cnt<<" }  "<<endl;
                cnt=1;
            }
        }
    //cout<<"**  "<<ans<<"  **"<<endl;
    sort(ans.begin(),ans.end());
    string ans_;
    for (int i=0; i<ans.size(); i++)
    {
        int j;
        for (j=0; j<i; j++)
            if (ans[i] == ans[j]) break;
        if (j == i) ans_.push_back (ans[i]);
    }
    //cout<<"**{ "<<ans_<<" }**"<<endl;
    cout<<ans_<<endl;
    k++;
    ans.erase();
    }
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
map<char, int>mp;
map<int, char>mp2;
void precal()
{
    int cnt = 0;
    for(char i = 'a'; i<='z'; i++)
    {
        mp[i] = cnt;
        mp2[cnt] = i;
        cnt++;
    }
}
int main()
{

    FAST_IO;
    int t;
    cin>>t;
    precal();
    while(t--)
    {
       string s;
       cin>>s;
       string ans = "";
       for(int i = 0; i<sz(s); )
       {
           char x = s[i];
           int j = i;
           set<char>st;
           int cnt = 0;
           int xx = 0;
           while(j<sz(s))
           {
               if(x!=s[j])break;
               st.insert(s[j]);
               j++;
               xx++;
               cnt++;
           }
           if(sz(st) == 1 && xx == 1)ans+=x;
           if(cnt == 0)i++;
           i+=cnt;
       }
       sort(ans.begin(), ans.end());
       map<char, bool>mpx;
      for(int i = 0; i<sz(ans); i++)
      {
          if(!mpx[ans[i]])

          {
              cout<<ans[i];
              mpx[ans[i]] = 1;
          }
      }
      cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
map<char, int>mp;
map<int, char>mp2;
void precal()
{
    int cnt = 0;
    for(char i = 'a'; i<='z'; i++)
    {
        mp[i] = cnt;
        mp2[cnt] = i;
        cnt++;
    }
}
int main()
{

    FAST_IO;
    int t;
    cin>>t;
    precal();
    while(t--)
    {
        string s;
        cin>>s;
        deque<int>dq;
        string res = "";
        for(auto x: s)dq.push_back(mp[x]);
        while(dq.size()>=2)
        {
            int x = dq.front();
            dq.pop_front();
            int y = dq.front();
            dq.pop_front();
            if(x!=y)
            {
                res+=x;
                res+=y;
            }
        }
        if(sz(dq))
        {
            res+=dq.front();
        }
        sort(res.begin(), res.end());
        map<int, bool>mpx;
        for(auto x: res)
        {
            if(!mpx[x])
            {
                cout<<mp2[x];
                mpx[x] = 1;
            }
        }
        cout<<endl;
    }
    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    const int MOD = 1e9 + 7;
    #define ll long long int
    #define pii pair<int, int>
    #define pll pair<ll, ll>
    #define pb push_back
    #define eb emplace_back
    #define ff first
    //#define ss second
    #define vi vector<int>
    #define vl vector<ll>
    #define vpii vector<pii>
    #define vpll vector<pll>
    #define si set<int>
    #define mpii map<int, int>
    #define prq priority_queue
    #define sz(s) (int) s.size()
    #define pf printf
    #define sf scanf
    #define pi 2 * acos (0.0)
    #define inf 1e9
    #define dbg cout<<"ok"<<endl;
    #define FOR(i, j, k) for(int i=(j); i<(k); i++)
    #define REV(i, j, k) for(int i=(n-1); i>=k; i--)
    #define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
    #define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
    #define mem(x, y) memset(x, y, sizeof(x))
    typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
    const double EPS = 1e-9;
    const int MXX = 2e5 + 5;

    int a[MXX];
    map<char, int>mp;
    map<int, char>mp2;
    void precal()
    {
        int cnt = 0;
        for(char i = 'a'; i<='z'; i++)
        {
            mp[i] = cnt;
            mp2[cnt] = i;
            cnt++;
        }
    }
    int main()
    {

        FAST_IO;
        int t;
        cin>>t;
        precal();
        while(t--)
        {
            string s;
            cin>>s;
            deque<int>dq;
            string res = "";
            for(auto x: s)dq.push_back(mp[x]);
            while(dq.size()>=2)
            {
                int x = dq.front();
                dq.pop_front();
                int y = dq.front();
                dq.pop_front();
                if(x!=y)
                {
                    res+=mp2[x];
                    res+=mp2[y];
                }
            }
            if(sz(dq))
            {
                res+=mp2[dq.front()];
            }
            sort(res.begin(), res.end());
            map<char, bool>mpx;
            for(auto x: res)
            {
                if(!mpx[x])
                {
                    cout<<x;
                    mpx[x] = 1;
                }
            }
            cout<<endl;
        }
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int main()
{

    FAST_IO;
    int t;
    cin>>t;
//    precal();
    while(t--)
    {
       string s;
       cin>>s;
       string ans = "";
       for(int i = 0; i<sz(s); i++)
       {
           if(i == 0)
           {
               if(s[i]!=s[i+1])ans+=s[i];
               continue;
           }
           if(i == sz(s)-1)
           {
               if(s[i]!=s[i-1] && i-1>=0)
               {
                   ans+=s[i];
               }
               continue;
           }
           if(s[i-1]!=s[i] && s[i]!=s[i+1])
           {
               ans+=s[i];
           }
       }
       sort(ans.begin(), ans.end());
       cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
int main()
{

    FAST_IO;
    int t;cin>>t;
    while(t--)
    {
       string s;cin>>s;
       string ss="";
       for(int i = 0; i<sz(s); i+=2)
       {
           if(s[i]==s[i+1])continue;
           else
           {
               ss+=s[i];
               if(i!=sz(s)-1)
               {
                   ss+=s[i+1];
               }
               else
               {
                   if(i == sz(s)-1)
                   {
                       if(s[i-1] == s[i])ss.pop_back();
                   }
               }
           }
       }
       sort(ss.begin(),ss.end());
       cout<<ss<<endl;
    }
    return 0;
}


    #include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    const int MOD = 1e9 + 7;
    #define ll long long int
    #define pii pair<int, int>
    #define pll pair<ll, ll>
    #define pb push_back
    #define eb emplace_back
    #define ff first
    //#define ss second
    #define vi vector<int>
    #define vl vector<ll>
    #define vpii vector<pii>
    #define vpll vector<pll>
    #define si set<int>
    #define mpii map<int, int>
    #define prq priority_queue
    #define sz(s) (int) s.size()
    #define pf printf
    #define sf scanf
    #define pi 2 * acos (0.0)
    #define inf 1e9
    #define dbg cout<<"ok"<<endl;
    #define FOR(i, j, k) for(int i=(j); i<(k); i++)
    #define REV(i, j, k) for(int i=(n-1); i>=k; i--)
    #define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
    #define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
    #define mem(x, y) memset(x, y, sizeof(x))
    typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
    const double EPS = 1e-9;
    const int MXX = 2e5 + 5;

    int a[MXX];
    int main()
    {

        FAST_IO;
        int t;cin>>t;
        while(t--)
        {
           string s;cin>>s;
           string ss="";
           set<char>st;
           for(int i = 0; i<sz(s); i++)
           {
               if(s[i]==s[i+1]){i++;}
               else
               {
                  st.insert(s[i]);
               }
           }
          for(auto x: st)cout<<x;
          cout<<endl;
        }
        return 0;
    }


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
map<char, int>mp;
map<int, char>mp2;
void precal()
{
    int cnt = 0;
    for(char i = 'a'; i<='z'; i++)
    {
        mp[i] = cnt;
        mp2[cnt] = i;
        cnt++;
    }
}
int main()
{

    FAST_IO;
    int t;
    cin>>t;
    precal();
    while(t--)
    {
        string s;
        cin>>s;
        deque<int>dq;
        string res = "";
        for(auto x: s)dq.push_back(mp[x]);
        while(dq.size()>=2)
        {
            int x = dq.front();
            dq.pop_front();
            int y = dq.front();
            if(x==y)dq.pop_front();
            if(x!=y)
            {
                res+=mp2[x];
            }
            //if(x!=y)dq.push_back(y);
        }
        if(sz(dq))
        {
            res+=mp2[dq.front()];
        }
        sort(res.begin(), res.end());
        map<char, bool>mpx;
        for(auto x: res)
        {
            if(!mpx[x])
            {
                cout<<x;
                mpx[x] = 1;
            }
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
map<char, int>mp;
map<int, char>mp2;
void precal()
{
    int cnt = 0;
    for(char i = 'a'; i<='z'; i++)
    {
        mp[i] = cnt;
        mp2[cnt] = i;
        cnt++;
    }
}
int main()
{

    FAST_IO;
    int t;
    cin>>t;
    precal();
    while(t--)
    {
        string s;
        cin>>s;
        deque<int>dq;
        string res = "";
        for(auto x: s)dq.push_back(mp[x]);
        while(dq.size()>=2)
        {
            int x = dq.front();
            dq.pop_front();
            int y = dq.front();
            dq.pop_front();
            if(x!=y)
            {
                res+=mp2[x];
                res+=mp2[y];
            }
        }
        if(sz(dq))
        {
            res+=mp2[dq.front()];
        }
        sort(res.begin(), res.end());
        map<char, int>mpx;
        for(auto x: res)mpx[x]++;
        for(auto x: res)
        {
            if(mpx[x] == 1)cout<<x;
        }
        cout<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Include for built in treap
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
#define ll long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define ff first
//#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define si set<int>
#define mpii map<int, int>
#define prq priority_queue
#define sz(s) (int) s.size()
#define pf printf
#define sf scanf
#define pi 2 * acos (0.0)
#define inf 1e9
#define dbg cout<<"ok"<<endl;
#define FOR(i, j, k) for(int i=(j); i<(k); i++)
#define REV(i, j, k) for(int i=(n-1); i>=k; i--)
#define rnd(a, b) ((((rand()<<15)^rand())%((b)-(a) + 1))+(a))
#define FAST_IO ios_base::sync_with_stdio(false),cin.tie(NULL)
#define mem(x, y) memset(x, y, sizeof(x))
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pb_ds;
const double EPS = 1e-9;
const int MXX = 2e5 + 5;

int a[MXX];
int main()
{

    FAST_IO;
    int t;cin>>t;
    while(t--)
    {
       string s;cin>>s;
       string ss="";
       for(int i = 0; i<sz(s); i+=2)
       {
           if(s[i]==s[i+1])continue;
           else
           {
               ss+=s[i];
               if(i!=sz(s)-1)ss+=s[i+1];
           }
       }
       sort(ss.begin(),ss.end());
       cout<<ss<<endl;
    }
    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    int t;
    cin>>t;
    while(t--){
        cin>>s;
        set <char> letter;
        for(int i=0; i<s.length(); i++){
            if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                letter.insert(s[i]);
            }
        }
        for(set<char>::iterator it = letter.begin(); it!=letter.end(); it++){
            cout<<*it;
        }
        cout<<"\n";
    }

    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    int a[26];
    int t;
    cin>>t;
    while(t--){
        for(int i=0; i<26; i++)a[i]=0;
        cin>>s;
        for(int i=0; i<s.length(); i++){
            if(i==0){
                if(s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
            else if(i==s.length()-1){
                if(s[i]!=s[i-1]){
                    a[s[i]-97]=1;
                }
            }
            else{
                if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
        }
        for(int i=0; i<26; i++){
            if(a[i]==1){
                printf("%c", i+97);
            }
        }
        printf("\n");
    }

    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a[26];
    int t;
    cin>>t;
    while(t--){
        for(int i=0; i<26; i++)a[i]=0;
        char s[505];
        scanf("%s", &s);
        for(int i=0; i<strlen(s); i++){
            if(i==0){
                if(s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
            else if(i==strlen(s)-1){
                if(s[i]!=s[i-1]){
                    a[s[i]-97]=1;
                }
            }
            else{
                if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
        }
        for(int i=0; i<26; i++){
            if(a[i]==1){
                printf("%c", i+97);
            }
        }
        printf("\n");
    }

    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a[26];
    int t;
    cin>>t;
    while(t--){
        for(int i=0; i<26; i++)a[i]=0;
        string s;
        cin>>s;
        for(int i=0; i<s.length(); i++){
            if(i==0){
                if(s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
            else if(i==s.length()-1){
                if(s[i]!=s[i-1]){
                    a[s[i]-97]=1;
                }
            }
            else{
                if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
        }
        for(int i=0; i<26; i++){
            if(a[i]==1){
                printf("%c", i+97);
            }
        }
        printf("\n");
    }

    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    int t;
    cin>>t;
    while(t--){
        set<char>letter;
        cin>>s;
        for(int i=0; i<s.length(); i++){
            int cnt=1;
            int temp = i;
            while(s[i+1]==s[i]){
                cnt++;
                i++;
            }
            if(cnt%2!=0){
                letter.insert(s[temp]);
            }
        }
        for(set<char>::iterator it = letter.begin(); it!=letter.end(); it++){
            cout<<*it;
        }
        cout<<"\n";
    }
    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a[26];
    int t;
    cin>>t;
    while(t--){
        for(int i=0; i<26; i++)a[i]=0;
        char s[505];
        scanf("%s", &s);
        int len = strlen(s);
        for(int i=0; i<len; i++){
            if(i==0){
                if(s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
            else if(i==len-1){
                if(s[i]!=s[i-1]){
                    a[s[i]-97]=1;
                }
            }
            else{
                if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
        }
        for(int i=0; i<26; i++){
            if(a[i]==1){
                printf("%c", i+97);
            }
        }
        printf("\n");
    }

    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s;
    int a[26];
    int t;
    cin>>t;
    while(t--){
        for(int i=0; i<26; i++)a[i]=0;
        cin>>s;
        for(int i=0; i<s.length(); i++){
            if(i==0){
                if(s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
            else if(i==s.length()-1){
                if(s[i]!=s[i-1]){
                    a[s[i]-97]=1;
                }
            }
            else{
                if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
        }
        for(int i=0; i<26; i++){
            if(a[i]==1){
                printf("%c", i+97);
            }
        }
        cout<<"\n";
    }

    return 0;
}


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

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int a[26];
    int t;
    cin>>t;
    while(t--){
        for(int i=0; i<26; i++)a[i]=0;
        char s[505];
        gets(s);
        int len = strlen(s);
        for(int i=0; i<len; i++){
            if(i==0){
                if(s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
            else if(i==len-1){
                if(s[i]!=s[i-1]){
                    a[s[i]-97]=1;
                }
            }
            else{
                if(s[i]!=s[i-1] && s[i]!=s[i+1]){
                    a[s[i]-97]=1;
                }
            }
        }
        for(int i=0; i<26; i++){
            if(a[i]==1){
                printf("%c", i+97);
            }
        }
        printf("\n");
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  int n=s.size()
   map<char,int>m;
   for(int i=0;i<s.size();i++)
   {
     if(i+1<n && s[i]==s[i+1])
     {
       m[s[i]]=0;
     }

     else if(m.find(s[i])==m.end())
     {
       m[s[i]]=1;
     }
   }

   for(auto i : m)
    if(i.second==1)cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  s="*"+s+"*";
  map<char,int>m,m2;
  for(int i=1;i<s.size()-1;i++)
  {
    m2[s[i]]++;
    if(s[i]!=s[i-1]&&s[i]!=s[i+1])
    {
     m[s[i]]++;
    }
  }
  for(auto i : m2)
  {
    if(i.second%2==1)
    m[i.first]++;
  }
  for(auto i : m)

  cout<<i.first<<"";

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  int n=s.size();
   map<char,int>m;
   for(int i=0;i<s.size();i++)
   {
     if(i+1<n &&  s[i]==s[i+1] && m.find(s[i])==m.end() )
     {
       m[s[i]]=0;
     }
     else if(i-1>=0 && s[i]==s[i-1] && m.find(s[i])==m.end())
     m[s[i]]=0;

     else
     {
       m[s[i]]=1;
     }
   }

   for(auto i : m)
    if(i.second==1)cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  int n=s.size();
   map<char,int>m;
   for(int i=0;i<s.size();i++)
   {
     if(i+1<n && s[i]==s[i+1])
     {
       m[s[i]]=0;
     }

     else if(m.find(s[i])==m.end())
     {
       m[s[i]]=1;
     }
   }

   for(auto i : m)
    if(i.second==1)cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  int n=s.size();
   map<char,int>m;
   for(int i=0;i<s.size();i++)
   {
     if(i+1<n &&  s[i]==s[i+1] )
     {
       m[s[i]]=0;
     }
     else if(i-1>=0 && s[i]==s[i-1])
     m[s[i]]=0;

     else
     {
       m[s[i]]=1;
     }
   }

   for(auto i : m)
    if(i.second==1)cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
   map<char,int>m;
   for(int i=0;i<s.size();i++)
   {
     if(i+1<n && s[i]==s[i+1])
     {
       m[s[i]]=0;
     }

     else if(m.find(s[i])==m.end())
     {
       m[s[i]]=1;
     }
   }

   for(auto i : m)
    if(i.second==1)cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  s="*"+s+"*";
  map<char,int>m;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]!=s[i-1]&&s[i]!=s[i+1])
    {
     m[s[i]]++;
    }
  }
  for(auto i : m)
  if(i.first!='*')
  cout<<i.first<<"";

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  s="*"+s+"*";
  map<char,int>m,m2;
  for(int i=1;i<s.size()-1;i++)
  {
    m2[s[i]]++;
    if(s[i]!=s[i+1])
    {
     m[s[i]]++;
    }
  }
  for(auto i : m2)
  {
    if(i.second%2==1)
    m[i.first]++;
  }
  for(auto i : m)
  cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  int n=s.size();
   map<char,int>m;
   for(int i=0;i<s.size();i++)
   {
     if(i+1<n && ( s[i]==s[i+1] || s[i]==s[i-1]))
     {
       m[s[i]]=0;
     }

     else
     {
       m[s[i]]=1;
     }
   }

   for(auto i : m)
    if(i.second==1)cout<<i.first;

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
  s="*"+s+"*";
  map<char,int>m;
  for(int i=0;i<s.size();i++)
  {
    if(s[i]!=s[i-1]&&s[i]!=s[i+1])
    {
     m[s[i]]++;
    }
  }
  for(auto i : m)
  if(i.first!='*')
  cout<<i.first<<" ";

  cout<<"\n";
}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{

 string s;
 cin>>s;
 set<char>st;

 for(int i=0;i<s.length();)
 {
   int j=i;
   int cnt=0;
   while(j<s.length() && s[j]==s[i])
   {
     cnt++; j++;
   }
  if(cnt&1)st.insert(s[i]);
   i=j;

 }

 for(auto i  : st)
 cout<<i;
 cout<<"\n";

}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 +7;

int32_t main()
{
     ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  #endif

int t;
cin>>t;
while(t--)
{
  string s;
  cin>>s;
   map<char,int>m;
   int n=s.size();
   for(int i=0;i<n-1;i++)
   {
     if(s[i]==s[i+1])
     s[i]='*',s[i+1]='*';
   }

   for(int i=0;i<s.length();i++)
   if(s[i]!='*')
   m[s[i]]++;

   for(auto i : m)
    cout<<i.first;

  cout<<"\n";
}

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    int count=0;
    string h="";
    for(int i=0;i<s.length()-1;i++)
      {
        if(s[i]==s[i+1])
        {
          count++;
        }
        else
        {
          if(count%2==0)
          {  h=h+s[i];

           }
          count=0;
        }
      }
     count=0;
      for(int i=s.length()-1;i>0;i--)
      {
     if(s[i]==s[i-1])
      {
         count++;
      }
      else
        break;
      }

      if(count>0&&count%2==0)
      {
        h=h+s[s.length()-1];
      }

      if(s.length()==1)
        h=h+s[0];

     if(s.length()>1)
     {
      if(s[s.length()-1]!=s[s.length()-2])
        h=h+s[s.length()-1];
     }

      sort(h.begin(),h.end());

      set<char> ss;

      for(int i=0;i<h.length();i++)
          ss.insert(h[i]);

        for(auto i: ss)
          cout<<i;

        cout<<"\n";
   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0&&s.length()!=1)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==s.length()-1&&s.length()!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
     { h=h+s[i];
     int g=0;

    for(int j=i-1;j>0;j--)
    {
      if(s[j]==s[j-1])
      g++;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }
     }
    }

   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;

    if(set.size()==0)
    {
      if(s.length()%2!=0)
        cout<<s[0];
    }
   cout<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0&&s.length()!=1)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==s.length()-1&&s.length()!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
      h=h+s[i];

     }
   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;
   cout<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0&&s.length()!=1)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==s.length()-1&&s.length()!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
     { h=h+s[i];
     int g=0;

    for(int j=i-1;j>0;j--)
    {
      if(s[j]==s[j-1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }
     }
    }

   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;

    if(set.size()==0)
    {
      if(s.length()%2!=0)
        cout<<s[0];
    }
   cout<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0&&s.length()!=1)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==s.length()-1&&s.length()!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
      h=h+s[i];
     int g=0;

    for(int j=i-1;j>0;j--)
    {
    if(s[j]==s[j-1])
      g++;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }
    }
   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;
   cout<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0&&s.length()!=1)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];

       int  g=0;

    for(int j=i+1;j<s.length()-1;j++)
    {
      if(s[j]==s[j+1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i+1];
       }
    }
    else if(i==s.length()-1&&s.length()!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];

      int g=0;

    for(int j=i-1;j>0;j--)
    {
      if(s[j]==s[j-1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
     { h=h+s[i];
     int g=0;

    for(int j=i-1;j>0;j--)
    {
      if(s[j]==s[j-1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }

        g=0;

    for(int j=i+1;j<s.length()-1;j++)
    {
      if(s[j]==s[j+1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i+1];
       }
     }
    }

   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;

    if(set.size()==0)
    {
      if(s.length()%2!=0)
        cout<<s[0];
    }
   cout<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==t-1&&t-1!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
      h=h+s[i];

     }
   }

   sort(h.begin(),h.end());

   cout<<h<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==t-1&&t-1!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
      h=h+s[i];

     }
   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;
   cout<<"\n";

   }

}


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

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

  int t;
  cin >>t;

   while(t--)
   {
    string s;
    cin >>s;
    string h="";
    for(int i=0;i<s.length();i++)
   {
    if(i==0&&s.length()!=1)
    {
      if(s[i]!=s[i+1])
        h=h+s[i];
    }
    else if(i==s.length()-1&&s.length()!=1)
    {
      if(s[i]!=s[i-1])
        h=h+s[i];

      int g=0;

    for(int j=i-1;j>0;j--)
    {
      if(s[j]==s[j-1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }
    }
    else
    {

    if(s[i]!=s[i+1]&&s[i]!=s[i-1])
     { h=h+s[i];
     int g=0;

    for(int j=i-1;j>0;j--)
    {
      if(s[j]==s[j-1])
      g++;
       else
        break;
     }
     if(g%2==0&&g>0)
       {
        h=h+s[i-1];
       }
     }
    }

   }

   sort(h.begin(),h.end());

    set<char> set;

    for(int i=0;i<h.size();i++)
      set.insert(h[i]);

    for(auto i : set)
   cout<<i;

    if(set.size()==0)
    {
      if(s.length()%2!=0)
        cout<<s[0];
    }
   cout<<"\n";

   }

}


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

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        //sort(word.begin(),word.end());
        int a[30];
        for(int i=0; i<30; i++)
            a[i]=0;
        for(int i=0; i<word.length(); i++)
        {
            int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                j++;
                t++;
            }
            if(t%2==0)
                //a[word[i]-'a']=1;
                cout<<word[i];
            i=j;

        }
        /*for(int k=0; k<30; k++)
            if(a[k]==1)
                cout<<char(k+'a');*/
        cout<<endl;
    }

    return 0;
}


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

int main()
{
    vector <char> v;
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        for(int i=0;i<word.length();i++)
        {
            int t=0;
            int j=i;
            while(j<word.length())
            {
                if(word[i]==word[j+1])
                {
                    t++;
                    j++;
                }
                else
                {
                    i=j;
                    if(t%2==0)
                        cout<<word[i];
                    break;
                }
            }
        }
        cout<<endl;
    }
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int a[30];
        for(int i=0; i<30; i++)
            a[i]=0;
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        for(int i=0; i<word.length(); i++)
        {
            int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                j++;
                t++;
            }
            if(t%2==0)
                a[word[i]-'a']=1;
            i=j;

        }
        for(int k=0; k<30; k++)
            if(a[k]==1)
                cout<<char(k+'a');
        cout<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
void rearrange(string word);

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        rearrange(word);
        cout<<endl;
    }

    return 0;
}

void rearrange(string word)
{
        int a[30];
        for(int i=0; i<30; i++)
            a[i]=0;
        for(int i=0; i<word.length(); i++)
        {
            int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                j++;
                t++;
            }
            if(t%2==0)
                a[word[i]-'a']=1;
            i=j;

        }
        for(int k=0; k<30; k++)
            if(a[k]==1)
                cout<<char(k+'a');
}


#include <iostream>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
void count_letters(string s);

int main()
{
    int n;
    cin>>n;
    string word;
    for(int i=0;i<n;i++)
    {
        cin>>word;
        count_letters(word);
        cout<<endl;
    }

    return 0;
}

void count_letters(string s)
{
    int a[s.length()];
    for(int i=0; i<s.length(); i++)
        a[i]=4;
    a[0]=0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]==s[i+1])
        {
            a[i]=1;
            a[i+1]=1;
        }
        else if(s[i]!=s[i+1])
            if (a[i]==1)
                a[i+1]=0;
            else
            {
                a[i]=0;
                a[i+1]=0;
            }

    }
    /*for(int i=0; i<s.length(); i++)
        cout<<a[i];*/
    vector <char> v;
    for(int i=0; i<s.length(); i++)
        if(a[i]==0 )
            v.push_back(s[i]);
    sort(v.begin(),v.end());
    cout<<v[0];
    for(int i=0; i<v.size()-1; i++)
    {
        if(v[i]==v[i+1])
            continue;
        else
            cout<<v[i+1];
    }
}


#include <bits/stdc++.h>
using namespace std;
void rearrange(string word);

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        rearrange(word);
        cout<<endl;
    }

    return 0;
}

void rearrange(string word)
{
        int a[30];
        for(int i=0; i<30; i++)
            a[i]=0;
        for(int i=0; i<word.length(); i++)
        {
            //int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                j++;
                //t++;
            }
            if(j-i%2==0)
                a[word[i]-'a']=1;
            i=j;

        }
        for(int k=0; k<30; k++)
            if(a[k]==1)
                cout<<char(k+'a');
}


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

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        //sort(word.begin(),word.end());
        int a[30];
        for(int i=0; i<30; i++)
            a[i]=0;
        for(int i=0; i<word.length(); i++)
        {
            //int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                j++;
                //t++;
            }
            if((j-i)%2==0)
                a[word[i]-'a']=1;
            i=j;

        }
        for(int k=0; k<30; k++)
            if(a[k]==1)
                cout<<char(k+'a');
        cout<<endl;
    }

    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        int a[30];
        for(int i=0; i<30; i++)
            a[i]=0;
        for(int i=0; i<word.length(); i++)
        {
            //int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                j++;
                //t++;
            }
            if((j-i)%2==0)
                a[word[i]-'a']=1;
            i=j;

        }
        for(int k=0; k<30; k++)
            if(a[k]==1)
                cout<<char(k+'a');
        cout<<endl;
    }

    return 0;
}


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

int main()
{
    vector <char> v;
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        for(int i=0; i<word.length(); i++)
        {
            int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
                j++;
            if((j-i)%2==0)
                cout<<word[i];
            i=j;

        }
        cout<<endl;
    }

    return 0;
}


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

int main()
{
    vector <char> v;
    int n;
    cin>>n;
    while(n--)
    {
        string word;
        cin>>word;
        sort(word.begin(),word.end());
        for(int i=0; i<word.length(); i++)
        {
            int t=0;
            int j=i;
            while(j+1<word.length() && word[i]==word[j+1])
            {
                t++;
                j++;
            }
            i=j;
            if(t%2==0)
                cout<<word[i];
        }
        cout<<endl;
    }

    return 0;
}


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

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

    int q; cin >> q;
    while(q--) {
        string s; cin >> s;
        map<char, bool> cor;

        if(s.size() == 1) {
            cout << s[0] << "\n";
            continue;
        }

        for(int i=1; i<s.size()-1; i++) {
            if(s[i] == s[i+1] || s[i] == s[i-1]) {
                continue;
            }
            cor[s[i]] = true;
        }
        if(s[s.size()-1] != s[s.size()-2])
            cor[s[s.size()-1]] = true;
        if(s[0] != s[1])
            cor[s[0]] = true;

        for(auto it = cor.begin(); it != cor.end(); it++) {
            cout << it->first;
        }
        cout << "\n";
    }
    return 0;
}


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

int main() {
    int t; cin >> t;
    while(t--) {
        string s; cin >> s;

        if(s.size() == 1) {
            cout << s << endl;
            continue;
        }

        map<char, bool> ok;
        int k(0);
        for(int i=0; i<s.size(); i++) {
            char tmp = s[i];
            while(s[++i] == tmp) {
                k++;
            }
            i--;
            if(k%2)
                ok[tmp] = true;
        }
        if(s[0] != s[1])
            ok[s[0]] = true;
        if(s[s.size()-1] != s[s.size()-2])
            ok[s[s.size()-1]] = true;

        for(auto &it : ok) {
            if(it.second) {
                cout << it.first;
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
    int t; cin >> t;
    while(t--) {
        string s; cin >> s;

        if(s.size() == 1)
            cout << s << endl;

        map<char, bool> ok;
        for(int i=1; i<s.size()-1; i++) {
            if(s[i] != s[i-1] && s[i] != s[i+1])
                ok[s[i]] = true;
        }
        if(s[0] != s[1])
            ok[s[0]] = true;
        if(s[s.size()-1] != s[s.size()-2])
            ok[s[s.size()-1]] = true;

        for(auto &it : ok) {
            if(it.second) {
                cout << it.first;
            }
        }
        cout << endl;
    }
    return 0;
}


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

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

    int q; cin >> q;
    while(q--) {
        string s; cin >> s;
        map<char, bool> cor;

        if(s.size() == 1) {
            cout << s << endl;
            continue;
        }

        int n = s.size();

        for(int i=1; i<n-1; i++) {
            if(s[i] != s[i+1] && s[i] != s[i-1]) {
                cor[s[i]] = true;
            }
        }
        if(s[n-1] != s[n-2])
            cor[s[n-1]] = true;
        if(s[0] != s[1])
            cor[s[0]] = true;

        for(auto it = cor.begin(); it != cor.end(); ++it) {
            cout << it->first;
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
    int t; cin >> t;
    while(t--) {
        string s; cin >> s;

        map<char, bool> ok;
        for(int i=0; i<s.size(); i++) {
            int k(0);
            char tmp = s[i];
            while(s[i] == tmp && i < s.size()) {
                k++;
                i++;
            }
            i--;
            if(k%2)
                ok[tmp] = true;
        }

        for(auto &it : ok) {
            if(it.second) {
                cout << it.first;
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
    int t; cin >> t;
    while(t--) {
        string s; cin >> s;

        if(s.size() == 1) {
            cout << s << endl;
            continue;
        }

        map<char, bool> ok;
        for(int i=1; i<s.size()-1; i++) {
            if(s[i] != s[i-1] && s[i] != s[i+1])
                ok[s[i]] = true;
        }
        if(s[0] != s[1])
            ok[s[0]] = true;
        if(s[s.size()-1] != s[s.size()-2])
            ok[s[s.size()-1]] = true;

        for(auto &it : ok) {
            if(it.second) {
                cout << it.first;
            }
        }
        cout << endl;
    }
    return 0;
}


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

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

    int q; cin >> q;
    while(q--) {
        string s; cin >> s;
        map<char, bool> cor;

        if(s.size() == 1) {
            cout << s[0] << "\n";
            continue;
        }

        for(int i=0; i<s.size()-1; i++) {
            if(s[i] == s[i+1]) {
                i++;
                continue;
            }
            cor[s[i]] = true;
        }
        if(s[s.size()-1] != s[s.size()-2])
            cor[s[s.size()-1]] = true;

        for(auto it = cor.begin(); it != cor.end(); it++) {
            cout << it->first;
        }
        cout << "\n";
    }
    return 0;
}


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

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

    int q; cin >> q;
    while(q--) {
        string s; cin >> s;
        map<char, bool> cor;

        if(s.size() == 1) {
            cout << s[0] << "\n";
            continue;
        }

        for(int i=1; i<s.size()-1; i++) {
            if(s[i] == s[i+1] || s[i] == s[i-1]) {
                i++;
                continue;
            }
            cor[s[i]] = true;
        }
        if(s[s.size()-1] != s[s.size()-2])
            cor[s[s.size()-1]] = true;
        if(s[0] != s[1])
            cor[s[0]] = true;

        for(auto it = cor.begin(); it != cor.end(); it++) {
            cout << it->first;
        }
        cout << "\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t,p;

    cin>>t;

    while(t--)
    {

        int n,i,h=0,j,k=0,q=1;
        string s;
        cin>>s;
        n=s.length();
        char c[n+1],b[n+1];
        strcpy(c, s.c_str());
        if(n==1)
        {
            b[h]=c[n-1];
            h++;
        }
        else
        {

                for(i=0;i<n;i++)
                {
                    if(c[i]==c[i+1])
                    {
                        q++;
                    }
                    else
                    {
                        if(q%2!=0)
                        {
                            b[h]=c[i];
                            h++;
                            q=1;
                        }
                        else
                            q=1;
                    }
                }

        }
        sort(b,b+h);
        for(i=0;i<h;i++)
        {
            if(i>0&&b[i]!=b[i-1])
            {
                cout<<b[i];
            }
            else if(i==0)
            {
                cout<<b[i];
            }
        }

            cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll                 long long
#define ra                 return a;
#define pb                 push_back
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define pqi                priority_queue<ll>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>>
#define inf                1e18L+1
#define endl               '\n'
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll tests=1;
    cin>>tests;
    while(tests--)
{
	string s;
	cin>>s;
	ll n;
	n=sz(s);
	ll presence[26]={0},key[26]={0};
	rep(i,0,n)
	{
		presence[s[i]-'a']=1;
		if(i)
		{
			if(i<n-1)
			{
				if(s[i]==s[i-1]||s[i]==s[i+1]);
				else
					key[s[i]-'a']=1;
			}
			else
				if(s[i]==s[i-1]);
			else
				key[s[i]-'a']=1;
		}
		else
		{
			if(i<n-1)
			{
				if(s[i]!=s[i+1])key[s[i]-'a']=1;

			}
			else key[s[i]-'a']=1;
		}
	}
	string ans;
	rep(i,0,26)
	{
		if(presence[i])if(key[i])ans+='a'+i;
	}
	cout<<ans<<endl;
}
    return 0;
}


#include<bits/stdc++.h>
#define ll                 long long
#define ra                 return a;
#define pb                 push_back
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define pqi                priority_queue<ll>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>>
#define inf                1e18L+1
#define endl               '\n'
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll tests=1;
    cin>>tests;
    while(tests--)
{
	string s;
	cin>>s;
	ll n;
	n=sz(s);
	ll presence[26]={0},key[26]={0};
	rep(i,0,n)
	{
		presence[s[i]-'a']=1;
		if(i)
		{
			if(i<n-1)
			{
				if(s[i]==s[i-1]||s[i]==s[i+1]);
				else
					key[s[i]-'a']=1;
			}
			else
				{
					if(s[i]==s[i-1]);
				else
					key[s[i]-'a']=1;
			}
		}
		else
		{
			if(i<n-1)
			{
				if(s[i]!=s[i+1])key[s[i]-'a']=1;

			}
			else key[s[i]-'a']=1;
		}
	}
	string ans;
	rep(i,0,26)
	{
		if(presence[i])if(key[i])ans+='a'+i;
	}
	cout<<ans<<endl;
}
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;
const int N = 200010;
int cnt = 1;
int a[N],t[N];
int search(int t,int i)
{
    if(t == i)
    {
        return cnt;
    }
    else
    {
        t = a[t];
        cnt++;
        search(t,i);
    }

}

int main()
{
    int q;
    cin >> q;
    while(q--)
    {
        int n;
        cin >> n;
        memset(a,0,sizeof a);
        memset(t,0,sizeof t);
        for(int i = 1;i <= n;i++)cin >> a[i];
        for(int i = 1;i <= n;i++)
        {
            cnt = 1;
            cnt = search(a[i],i);
            cout << cnt ;
            if(i != n)cout << " ";
        }
        puts("");
    }

    return 0;
}


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

void solve()
{
    int n;
    cin >> n;
    vector <int> a(n);
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        a[i]--;
    }
    vector<int> q(n,-1);
    for(int i = 0;i < n;i++)
    {
        if(q[i] == -1)
        {
            q[i] = 1;
            for(int j = a[i];j != i;j = a[j])
            {
                q[i]++;
            }
            for(int j = a[i];j != i;j = a[j])
            {
                q[j] = q[i];
            }
        }
    }
    for(int i = 0;i < n;i++)cout << q[i] << " \n"[i == n -1];
}

int main()
{
    int q;
    cin >> q;
    while(q--)
    {
        solve();
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#define cinspeed ios::sync_with_stdio (false);cin.tie(false);
using namespace std;

void solve()
{
    cinspeed;
    int n;
    cin >> n;
    vector <int> a(n);
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
        a[i]--;
    }
    vector<int> q(n,-1);
    for(int i = 0;i < n;i++)
    {
        if(q[i] == -1)
        {
            q[i] = 1;
            for(int j = a[i];j != i;j = a[j])
            {
                q[i]++;
            }
            for(int j = a[i];j != i;j = a[j])
            {
                q[j] = q[i];
            }
        }
    }
    for(int i = 0;i < n;i++)cout << q[i] << " \n"[i == n -1];

}

int main()
{
    int q;
    cin >> q;
    while(q--)
    {
        solve();
    }
    return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define AmrYassen ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2 * 1e5;
vector<ll> tmp, freq(N);
bool visited[N];
ll ans;
void dfs(ll node, vector<ll> v[]) {
	ans++;
	visited[node] = true;
	tmp.push_back(node);
	for (auto i : v[node]) {
		if (!visited[i]) {
			dfs(i, v);
		}
	}
}
int main() {
	AmrYassen
	ll n;
	cin >> n;
	while (n--) {
		ll m;
		cin >> m;
		vector<ll> vv, v[N];
		for (int i = 0; i < m; i++) {
			ll a;
			cin >> a;
			vv.push_back(a);
			v[i + 1].push_back(a);
			v[a].push_back(i + 1);
		}
		for (int i = 0; i < vv.size(); i++) {
			if (!visited[vv[i]]) {
				dfs(vv[i], v);
				for (int y = 0; y < tmp.size(); y++) {
					freq[tmp[y]] = ans;
				}
				tmp.clear();
				ans = 0;
			}
			cout << freq[vv[i]] << " ";
		}
		cout << endl;
		freq.clear();
		memset(visited, false, sizeof visited);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define AmrYassen ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2 * 1e5;
ll minn = LONG_LONG_MAX, maxx;
vector<ll> v(300, 0);
ll rec(ll value, ll i) {
	if (value == i + 1)
		return 1;
	return rec(v[value - 1], i) + 1;
}
int main() {
	AmrYassen
	ll n;
	cin >> n;
	while (n--) {
		ll a;
		cin >> a;
		for (int i = 0; i < a; i++) {
			cin >> v[i];
		}
		for (int i = 0; i < a; i++) {
			ll q = rec(v[i], i);
			cout << q << " ";
		}
		cout << endl;
		v.clear();
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define AmrYassen ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 4 * 1e5;
vector<ll> tmp, freq(N), v[N];
bool visited[N];
ll ans;
void dfs(ll node) {
	ans++;
	visited[node] = true;
	tmp.push_back(node);
	for (auto i : v[node]) {
		if (!visited[i]) {
			dfs(i);
		}
	}
}
int main() {
	AmrYassen
	ll n;
	cin >> n;
	while (n--) {
		ll m;
		cin >> m;
		vector<ll> vv;
		for (int i = 0; i < m; i++) {
			ll a;
			cin >> a;
			vv.push_back(a);
			v[i + 1].push_back(a);
			v[a].push_back(i + 1);
		}
		for (int i = 0; i < vv.size(); i++) {
			if (!visited[vv[i]]) {
				dfs(vv[i]);
				for (int y = 0; y < tmp.size(); y++) {
					freq[tmp[y]] = ans;
				}
				tmp.clear();
				ans = 0;
			}
			cout << freq[vv[i]] << " ";
		}
		cout << endl;
		freq.clear();
		for (int i = 0; i < vv.size(); i++) {
			v[vv[i]].clear();
		}
		memset(visited, false, sizeof visited);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define AmrYassen ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 4 * 1e5;
vector<ll> tmp, freq(N);
bool visited[N];
ll ans;
void dfs(ll node, vector<ll> v[]) {
	ans++;
	visited[node] = true;
	tmp.push_back(node);
	for (auto i : v[node]) {
		if (!visited[i]) {
			dfs(i, v);
		}
	}
}
int main() {
	AmrYassen
	ll n;
	cin >> n;
	while (n--) {
		ll m;
		cin >> m;
		vector<ll> vv, v[N];
		for (int i = 0; i < m; i++) {
			ll a;
			cin >> a;
			vv.push_back(a);
			v[i + 1].push_back(a);
			v[a].push_back(i + 1);
		}
		for (int i = 0; i < vv.size(); i++) {
			if (!visited[vv[i]]) {
				dfs(vv[i], v);
				for (int y = 0; y < tmp.size(); y++) {
					freq[tmp[y]] = ans;
				}
				tmp.clear();
				ans = 0;
			}
			cout << freq[vv[i]] << " ";
		}
		cout << endl;
		freq.clear();
		memset(visited, false, sizeof visited);
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define AmrYassen ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int mod = 1e9 + 7;
ll minn = LONG_LONG_MAX, maxx;
ll rec(ll arr[],ll value,ll i){
	if(value==i+1)return 0;
	return rec(arr,arr[value-1],i)+1;
}
int main() {
	AmrYassen
	ll n;
	cin >> n;
	while (n--) {
		ll a;
		cin >> a;ll arr[a];
		for (int i = 0; i < a; i++) {
			cin >>arr[i];
		}
		for (int i = 0; i <a; i++) {
ll q=rec(arr,arr[i],i);cout<<q+1<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define AmrYassen ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int mod = 1e9 + 7;
const int N = 2 * 1e5;
ll minn = LONG_LONG_MAX, maxx;
vector<ll> v(N, 0);
ll rec(ll value, ll i) {
	if (value == i + 1)
		return 1;
	return rec(v[value - 1], i) + 1;
}
int main() {
	AmrYassen
	ll n;
	cin >> n;
	while (n--) {
		ll a;
		cin >> a;
		for (int i = 0; i < a; i++) {
			cin >> v[i];
		}
		for (int i = 0; i < a; i++) {
			ll q = rec(v[i], i);
			cout << q << " ";
		}
		cout << endl;
		v.clear();
	}
	return 0;
}


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

#define ll long long
#define pii pair<ll ,ll>
#define pb push_back
#define mxx 1000
#define PI acos(-1.0)
#define mod 1000000007
#define FOR(i,j,n) for(int i=j;i<n;i++)
map <int, int> vis;
void DFS(vector<int> G[], int u)
{
    // cout << u << endl;
    vis[u] = 1;
    int  v;

    for(v=0; v<G[u].size(); v++)
    {
        if(vis[G[u][v]] == 0)
        {
            vis[G[u][v]] = 1;
            DFS(G,G[u][v]);
        }
        ///else ;
    }
}
int main()
{
    int n, q;
    scanf("%d", &q);
    while(q--)
    {
        scanf("%d", &n);
        int a[n+5];

        for(int i=1; i<=n; i++)
        {
            scanf("%d", &a[i]);
            //cin>>a[i];

        }
        vector<int> G[n+5];
        map<int, int>:: iterator it;
        for(int i=1; i<=n; i++)
        {

            G[a[i]]. push_back(a[a[i]]);
            G[a[a[i]]]. push_back(a[i]);
        }
        int ans[n+5];
        for(int i=1; i<=n; i++)
        {
            if(vis[a[i]] == 0)
                DFS(G,a[i]);
            for(it = vis.begin(); it!= vis.end(); it++)
            {

                int p = it->first;
                ans[p] = vis.size();
            }
            vis.clear();
        }
        FOR(i,1,n+1)
        {
            printf("%d ", ans[i]);
        }
        printf("\n");

    }
}


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

#define ll long long
#define pii pair<ll ,ll>
#define pb push_back
#define mxx 1000
#define PI acos(-1.0)
#define mod 1000000007
#define FOR(i,j,n) for(int i=j;i<n;i++)
map <int, int> vis;
void DFS(vector<int> G[], int u)
{
   // cout << u << endl;
    vis[u] = 1;
    int  v;

    for(v=0; v<G[u].size(); v++)
    {
        if(vis[G[u][v]] == 0)
        {
            vis[G[u][v]] = 1;
            DFS(G,G[u][v]);
        }
        ///else ;
    }
}
int main()
{
    int n, q;
    scanf("%d", &q);
    while(q--)
    {
        scanf("%d", &n);
        int a[n+5];

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

        }
        vector<int> G[n+5];
        map<int, int>:: iterator it;
        for(int i=1; i<=n; i++)
        {

            G[a[i]]. push_back(a[a[i]]);
            G[a[a[i]]]. push_back(a[i]);
        }
        int ans[n+5];
        for(int i=1; i<=n; i++)
        {
            if(vis[a[i]] == 0)
                DFS(G,a[i]);
            for(it = vis.begin(); it!= vis.end(); it++)
            {

                int p = it->first;
                ans[p] = vis.size();
            }
            vis.clear();
        }
        FOR(i,1,n+1){

        cout << ans[i] << " ";
        }
        cout << endl;

    }
}


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

#define ll long long
#define pii pair<ll ,ll>
#define pb push_back
#define mxx 1000
#define PI acos(-1.0)
#define mod 1000000007
#define FOR(i,j,n) for(int i=j;i<n;i++)
map <int, int> vis;
void DFS(vector<int> G[], int u)
{
    // cout << u << endl;
    vis[u] = 1;
    int  v;

    for(v=0; v<G[u].size(); v++)
    {
        if(vis[G[u][v]] == 0)
        {
            vis[G[u][v]] = 1;
            DFS(G,G[u][v]);
        }
        ///else ;
    }
}
int main()
{
    int n, q;
    scanf("%d", &q);
    map<int, int>:: iterator it;
    while(q--)
    {
        scanf("%d", &n);
        int a[n+5];

        for(int i=1; i<=n; i++)
        {
            scanf("%d", &a[i]);
            //cin>>a[i];

        }
        vector<int> G[n+5];

        for(int i=1; i<=n; i++)
        {
            G[a[i]]. push_back(a[a[i]]);
            G[a[a[i]]]. push_back(a[i]);
        }
        int ans[n+5];
        for(int i=1; i<=n; i++)
        {
            if(vis[a[i]] == 0)
            {
                DFS(G,a[i]);
                for(it = vis.begin(); it!= vis.end(); it++)
                {

                    int p = it->first;
                    ans[p] = vis.size();
                }
                vis.clear();
            }
        }
        FOR(i,1,n+1)
        {
            printf("%d ", ans[i]);
        }
        printf("\n");

    }
}


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

#define ll long long
#define pii pair<ll ,ll>
#define pb push_back
#define mxx 1000
#define PI acos(-1.0)
#define mod 1000000007
#define FOR(i,j,n) for(int i=j;i<n;i++)
map <int, int> vis;
map <int, int> id;
void DFS(vector<int> G[], int u)
{
    // cout << u << endl;
    vis[u] = 1;
    id[u] = 1;
    int  v;

    for(v=0; v<G[u].size(); v++)
    {
        if(vis[G[u][v]] == 0)
        {
            vis[G[u][v]] = 1;
            id[G[u][v]] = 1;
            DFS(G,G[u][v]);
        }
        ///else ;
    }
}
int main()
{
    int n, q;
    scanf("%d", &q);
    while(q--)
    {
        scanf("%d", &n);
        int a[n+5];

        for(int i=1; i<=n; i++)
        {
            scanf("%d", &a[i]);
            //cin>>a[i];

        }
        vector<int> G[n+5];
        map<int, int>:: iterator it;
        for(int i=1; i<=n; i++)
        {
            G[a[i]]. push_back(a[a[i]]);
            G[a[a[i]]]. push_back(a[i]);
        }
        int ans[n+5];
        for(int i=1; i<=n; i++)
        {
            if(vis[a[i]] == 0)
            {
                DFS(G,a[i]);
                //cout << id.size()<<endl;
                for(it = id.begin(); it!= id.end(); it++)
                {

                    int p = it->first;
                    ans[p] = id.size();
                }
                id.clear();
            }
        }
        FOR(i,1,n+1)
        {
            printf("%d ", ans[i]);
        }
        printf("\n");
        vis.clear();

    }
}


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

#define ll long long
#define pii pair<ll ,ll>
#define pb push_back
#define mxx 1000
#define PI acos(-1.0)
#define mod 1000000007

int main()
{
    int q;
   scanf("%d", &q);
    while(q--)
    {
        int n ;
        scanf("%d", &n);
        int a[n+5];
        int b[n+5];
        for(int i=1; i<=n; i++)
        {
            scanf("%d", &a[i]);
            b[i] = a[i];
        }
        int f=1;

        for(int i=1; i<=n; i++)
        {
            int k = i;
            while(b[i] != i)
            {
                b[i] = a[a[k]];
                f++;
                k = a[k];
            }
            printf("%d ", f);
            f=1;
        }
        printf("\n");
    }

}


#include<iostream>
#include<list>
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
    long a,s,d,n,t,q[200001],r[200001]={0};
    cin>>t;
    list<long>w,e;
    while(t--)
    {
        //cin>>n;
        scanf("%ld",&n);
        for(a=1;a<=n;a++)
        {
            //cin>>q[a];
            scanf("%ld",&q[a]);

        }
        for(a=1;a<=n;a++)
        {
            if(r[a]==0)
            {
                w.push_back(q[a]);

            d=1;
            while(!w.empty())
            {
                s=w.front();
               // w.pop_front();
                if(a==s)
                {

                    break;
                }
                else
                {
                    w.push_front(q[s]);
                    d++;
                }
            }
              while(!w.empty())
              {
                  r[w.front()]=d;
                  w.pop_front();
              }}
        }
        for(a=1;a<=n;a++)
        {
            cout<<r[a]<<" ";
            r[a]=0;
        }
        cout<<"\n";

    }
}


#include<iostream>
#include<list>
using namespace std;
int main()
{
    long a,s,d,n,t,q[200000];
    cin>>t;
    list<long>w;
    while(t--)
    {
        cin>>n;
        for(a=1;a<=n;a++)
        {
            cin>>q[a];
        }
        for(a=1;a<=n;a++)
        {
            w.push_back(q[a]);
            d=0;
            while(!w.empty())
            {
               d++;
                s=w.front();
                w.pop_front();
                if(s==a)
                {
                    //w.clear();
                    cout<<d<<" ";
                    break;
                }
                else
                {
                    w.push_back(q[s]);
                }
            }

        }
    cout<<"\n";
    }
}


#include<iostream>
#include<list>
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
    long a,s,d,n,t,q[200000],r[200000]={0};
    cin>>t;
    list<long>w,e;
    while(t--)
    {
        //cin>>n;
        scanf("%ld",&n);
        for(a=1;a<=n;a++)
        {
            //cin>>q[a];
            scanf("%ld",&q[a]);

        }
        for(a=1;a<n;a++)
        {
            if(r[a]==0)
            {
                w.push_back(q[a]);
            }
            d=1;
            while(!w.empty())
            {
                s=w.front();
               // w.pop_front();
                if(a==s)
                {

                    break;
                }
                else
                {
                    w.push_front(q[s]);
                    d++;
                }
            }
              while(!w.empty())
              {
                  r[w.front()]=d;
                  w.pop_front();
              }
        }
        for(a=1;a<=n;a++)
        {
            cout<<r[a]<<" ";
            r[a]=0;
        }
        cout<<"\n";

    }
}


#include<iostream>
#include<list>
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
    long a,s,d,n,t,q[200000],r[200000]={0};
    cin>>t;
    list<long>w,e;
    while(t--)
    {
        //cin>>n;
        scanf("%ld",&n);
        for(a=1;a<=n;a++)
        {
            //cin>>q[a];
            scanf("%ld",&q[a]);

        }
        for(a=1;a<=n;a++)
        {
            if(r[a]==0)
            {
                w.push_back(q[a]);
            }
            d=1;
            while(!w.empty())
            {
                s=w.front();
               // w.pop_front();
                if(a==s)
                {

                    break;
                }
                else
                {
                    w.push_front(q[s]);
                    d++;
                }
            }
              while(!w.empty())
              {
                  r[w.front()]=d;
                  w.pop_front();
              }
        }
        for(a=1;a<=n;a++)
        {
            cout<<r[a]<<" ";
            r[a]=0;
        }
        cout<<"\n";

    }
}


#include<iostream>
#include<list>
using namespace std;
int main()
{
    long a,s,d,n,t,q[2020];
    cin>>t;
    list<long>w;
    while(t--)
    {
        cin>>n;
        for(a=1;a<=n;a++)
        {
            cin>>q[a];
        }
        for(a=1;a<=n;a++)
        {
            w.push_back(q[a]);
            d=0;
            while(!w.empty())
            {
               d++;
                s=w.front();
                w.pop_front();
                if(s==a)
                {
                    //w.clear();
                    cout<<d<<" ";
                    break;
                }
                else
                {
                    w.push_back(q[s]);
                }
            }

        }
    cout<<"\n";
    }
}


#include<iostream>
#include<list>
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
    long a,s,d,n,t,q[200000],r[200000]={0};
    cin>>t;
    list<long>w,e;
    while(t--)
    {
        //cin>>n;
        scanf("%ld",&n);
        for(a=1;a<=n;a++)
        {
            //cin>>q[a];
            scanf("%ld",&q[a]);

        }
        for(a=1;a<=n;a++)
        {
            if(r[a]==0)
            {
                w.push_back(q[a]);

            d=1;
            while(!w.empty())
            {
                s=w.front();
               // w.pop_front();
                if(a==s)
                {

                    break;
                }
                else
                {
                    w.push_front(q[s]);
                    d++;
                }
            }
              while(!w.empty())
              {
                  r[w.front()]=d;
                  w.pop_front();
              }}
        }
        for(a=1;a<=n;a++)
        {
            cout<<r[a]<<" ";
            r[a]=0;
        }
        cout<<"\n";

    }
}