#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	ll n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      ll n=s1.size();
      ll m=s2.size();
     // cout<<s1<<" "<<s2<<endl;
      string temp=s1;
      sort(temp.begin(), temp.end());

     int flag=0;
      for (int i = 0; i <n;i++)
      {

        if(temp[i]==s1[i])
          continue;
        else
        {

          for(int j=i+1;j<n;j++)
          {
            if(s1[j]==temp[i])
            {
             // cout<<"found at: "<<j<<endl;
              flag=1;
              swap(s1[i],s1[j]);
              break;
            }
          }

        }
        if(flag==1)
          break;

      }

      if(s1<s2)
      {
        cout<<s1<<"\n";

      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
     // cout<<s1<<" "<<s2<<endl;
      string temp=s1;
      sort(temp.begin(), temp.end());

      for (int i = 0; i <n; ++i)
      {

        if(temp[i]==s1[i])
          continue;
        else
        {

          for(int j=i+1;j<n;j++)
          {
            if(s1[j]==temp[i])
            {
              swap(s1[i],s1[j]);
              break;
            }
          }
          break;

        }

      }

      if(s1<s2)
      {
        cout<<s1<<"\n";

      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
      string temp=s1;
      sort(temp.begin(),temp.end());
      if(temp>s2)
      {
        cout<<"---\n";
        continue;
      }

      int never=0;
      for (int i = 0; i < min(n,m); ++i)
      {
        if(s1[i]==s2[i])
        {
          continue;
        }
        else
        {
          if(s1[i]<s2[i])
          {
            break;

           }
          else
          {
            int j=i+1;
            int flag=0;
            int index;
            for (int x=j;x<n;x++)
            {
              if(s1[x]<s2[i])
              {
                index=x;
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              char a=s1[i];
              char b=s1[index];
              s1[i]=b;
              s1[index]=a;
              break;
            }
            else
            {
              never=1;
              break;
            }
          }
        }
      }

      if(never==0)
      {
        cout<<s1<<endl;
      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
     // cout<<s1<<" "<<s2<<endl;
      string temp=s1;
      sort(temp.begin(), temp.end());

      for (int i = 0; i <n; ++i)
      {

        if(temp[i]==s1[i])
          continue;
        else
        {

          for(int j=i+1;j<n;j++)
          {
            if(s1[j]==temp[i])
            {
              //cout<<"vdfkjv";
              swap(s1[i],s1[j]);
              break;
            }
          }
          break;

        }

      }

      if(s1<s2)
      {
        cout<<s1<<"\n";

      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	ll n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      ll n=s1.size();
      ll m=s2.size();
     // cout<<s1<<" "<<s2<<endl;

      string temp=s1;
      sort(temp.begin(), temp.end());

     int flag=0;
      for (int i = 0; i <n;i++)
      {

        if(temp[i]==s1[i])
          continue;
        else
        {

          for(int j=i+1;j<n;j++)
          {
            if(s1[j]==temp[i])
            {

              swap(s1[i],s1[j]);
              if(s1<s2)
              {
                flag=1;
                break;
              }
              swap(s1[j],s1[i]);

            }
          }

        }

        if(flag==1)
          break;

      }

      if(s1<s2)
      {
        cout<<s1<<"\n";

      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
      string temp=s1;
      sort(temp.begin(),temp.end());
      if(temp>s2)
      {
        cout<<"---\n";
        continue;
      }

      int never=0;
      for (int i = 0; i < min(n,m); ++i)
      {
        if(s1[i]==s2[i])
        {
          continue;
        }
        else
        {
          if(s1[i]<s2[i])
          {
            break;

           }
          else
          {
            int j=i+1;
            int flag=0;
            int index;
            for (int x=j;x<n;x++)
            {
              if(s1[x]<s2[i])
              {
                index=x;
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              swap(s1[i],s1[index]);

              if(s1<s2)
              break;
              else
                continue;
            }
            else
            {
              never=1;
              break;
            }
          }
        }
      }

      if(never==0)
      {
        cout<<s1<<endl;
      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
      if(n<m)
      {
        cout<<"---\n";
        continue;
      }
      string temp=s1;
      sort(temp.begin(),temp.end());
      if(temp>s2)
      {
        //cout<<temp;
        cout<<"---\n";
        continue;
      }

      int never=0;
      for (int i = 0; i < min(n,m); ++i)
      {
        if(s1[i]==s2[i])
        {
          continue;
        }
        else
        {
          if(s1[i]<s2[i])
          {
            break;

           }
          else
          {
            int j=i+1;
            int flag=0;
            int index;
            //cout<<"j hai "<<j<<endl;
            for (int x=j;x<n;x++)
            {
              if(s1[x]<=s2[i])
              {
                index=x;
               // cout<<"INDEX HAI: "<<index<<"\n";
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              swap(s1[i],s1[index]);

              if(s1<s2)
              break;
              else
                continue;
            }
            else
            {
              never=1;
              break;
            }
          }
        }
      }

      if(never==0)
      {
        //cout<<"kvf";
        cout<<s1<<endl;
      }
      else
      {
        //cout<<"vf ";
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
      string temp=s1;
      sort(temp.begin(),temp.end());
      if(temp>s2)
      {
        //cout<<temp;
        cout<<"---\n";
        continue;
      }

      int never=0;
      for (int i = 0; i < min(n,m); ++i)
      {
        if(s1[i]==s2[i])
        {
          continue;
        }
        else
        {
          if(s1[i]<s2[i])
          {
            break;

           }
          else
          {
            int j=i+1;
            int flag=0;
            int index;
            //cout<<"j hai "<<j<<endl;
            for (int x=j;x<n;x++)
            {
              if(s1[x]<=s2[i])
              {
                index=x;
               // cout<<"INDEX HAI: "<<index<<"\n";
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              swap(s1[i],s1[index]);

              if(s1<s2)
              break;
              else
                continue;
            }
            else
            {
              never=1;
              break;
            }
          }
        }
      }

      if(never==0)
      {
        //cout<<"kvf";
        cout<<s1<<endl;
      }
      else
      {
        //cout<<"vf ";
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
     // cout<<s1<<" "<<s2<<endl;

      for (int i = 0; i < min(n,m); ++i)
      {

          if(s1[i]<s2[i])
          {
            //cout<<"mai chala  hu";
            break;

           }
          else
          {

            int flag=0;
            int index;
            //cout<<"j hai "<<i+1<<endl;
            for (int x=i+1;x<n;x++)
            {
              if(s1[x]<=s2[i])
              {
                index=x;
               // cout<<"INDEX HAI: "<<index<<"\n";
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              swap(s1[i],s1[index]);

              if(s1<s2)
              break;
              else
                continue;
            }

          }

      }

      // cout<<s1<<" "<<s2<<endl;

      if(s1<s2)
      {
        cout<<s1<<"\n";
      }
      else
      {
        //cout<<"v f";
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
     // cout<<s1<<" "<<s2<<endl;

      for (int i = 0; i <n; ++i)
      {

          if(s1[i]<s2[i])
          {
            //cout<<"mai chala  hu";
            break;

           }
          else
          {

            int flag=0;
            int index;
            //cout<<"j hai "<<i+1<<endl;
            for (int x=i+1;x<n;x++)
            {
              if(s1[x]<=s2[i])
              {
                index=x;
               // cout<<"INDEX HAI: "<<index<<"\n";
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              swap(s1[i],s1[index]);

              if(s1<s2)
              break;
              else
                continue;
            }

          }

      }

      // cout<<s1<<" "<<s2<<endl;

      if(s1<s2)
      {
        cout<<s1<<"\n";
      }
      else
      {
        //cout<<"v f";
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();
     // cout<<s1<<" "<<s2<<endl;
      string temp=s1;
      sort(temp.begin(), temp.end());

     int flag=0;
      for (int i = 0; i <n; ++i)
      {

        if(temp[i]==s1[i])
          continue;
        else
        {

          for(int j=i+1;j<n;j++)
          {
            if(s1[j]==temp[i])
            {
             // cout<<"found at: "<<j<<endl;
              flag=1;
              swap(s1[i],s1[j]);
              break;
            }
          }

        }
        if(flag==1)
          break;

      }

      if(s1<s2)
      {
        cout<<s1<<"\n";

      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	int n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      int n=s1.size();
      int m=s2.size();

      string temp=s1;
      sort(temp.begin(),temp.end());
      if(temp>=s2)
      {
        //cout<<temp;
        cout<<"---\n";
        continue;
      }

      for (int i = 0; i < min(n,m); ++i)
      {

        if(s1[i]==s2[i])
        {
          continue;
        }
        else
        {
          if(s1[i]<s2[i])
          {
            break;

           }
          else
          {
            int j=i+1;
            int flag=0;
            int index;
            //cout<<"j hai "<<j<<endl;
            for (int x=j;x<n;x++)
            {
              if(s1[x]<=s2[i])
              {
                index=x;
               // cout<<"INDEX HAI: "<<index<<"\n";
                flag=1;
                break;
              }
            }
            if(flag==1)
            {
              swap(s1[i],s1[index]);

              if(s1<s2)
              break;
              else
                continue;
            }

          }
        }
      }

      // cout<<s1<<" "<<s2<<endl;

      if(s1<s2)
      {
        cout<<s1<<"\n";
      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long  long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;

int main()
{
	#ifndef ONLINE_JUDGE

		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout);

	#endif
	ll n,m,t;
	cin>>t;
	while(t--)
	{
			string s1,s2;
      cin>>s1>>s2;
      ll n=s1.size();
      ll m=s2.size();
     // cout<<s1<<" "<<s2<<endl;
      if(s1<s2)
      {
        cout<<s1<<endl;
        continue;
      }

      string temp=s1;
      sort(temp.begin(), temp.end());

     int flag=0;
      for (int i = 0; i <n;i++)
      {

        if(temp[i]==s1[i])
          continue;
        else
        {

          for(int j=i+1;j<n;j++)
          {
            if(s1[j]==temp[i])
            {
             // cout<<"found at: "<<j<<endl;
              flag=1;
              swap(s1[i],s1[j]);
              break;
            }
          }

        }

        if(flag==1)
          break;

      }

      if(s1<s2)
      {
        cout<<s1<<"\n";

      }
      else
      {
        cout<<"---\n";
      }

	}

return 0;
}


/*input
3
OS KSK
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ll n;
	cin>>n;
	string s,s1;char t;
	f(k,0,n)
	{
		cin>>s>>s1;
		f(i,0,sz(s))
		{
			if(s[i]<s1[i])
			{
				cout<<s<<endl;
				break;
			}
			else if(s[i]==s1[i] && sz(s1)<sz(s) && i==sz(s1))
			{
				cout<<"---"<<endl;
			}
			else if(s[i]==s1[i] && i==sz(s))
			{
				cout<<s<<endl;
			}
			else if(s[i]==s1[i])
			{
				//cout<<s[i]<<endl;
				continue;
			}
			else
			{
				f(j,i+1,sz(s))
				{
					//cout<<s[j]<<" "<<s1[i]<<endl;
					if(s[j]<=s1[i])
					{
						t=s[j];
						s[j]=s[i];
						s[i]=t;
						if(s<s1)
						{
							cout<<s<<endl;
						}
						else
							cout<<"---"<<endl;
						break;
					}
					else if(j==sz(s)-1)
					{
						cout<<"---"<<endl;
						break;
					}
				}
				break;
			}

		}
	}
}


/*input
3
AZAMON APPLE
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ll n;
	cin>>n;
	string s,s1,s2;char t;
	f(k,0,n)
	{
		cin>>s>>s1;
		s2=s;
		sort(all(s2));
		if(s2>=s1)
			cout<<"---"<<endl;
		else if(s<s1)
			cout<<s<<endl;
		else
		{
		f(i,0,sz(s))
		{
			if(s[i]>s1[i])
			{
			f(j,i+1,sz(s))
			{
					//cout<<s[j]<<" "<<s1[i]<<endl;
					if(s[j]<=s1[i])
					{
						t=s[j];
						s[j]=s[i];
						s[i]=t;
						if(s<=s1)
						{
							cout<<s<<endl;
						}
						else
							cout<<"---"<<endl;
						break;
					}
				}
				break;
			}
		}
	}
}
}


/*input
3
AZAMON APPLE
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll n;
	cin>>n;
	string s,s1,s2;char temp1;ll x=0;
	f(k,0,n)
	{
		cin>>s>>s1;x=0;ll y=0;
		//cout<<s<<" "<<s1<<endl;
		f(i,0,sz(s))
		{
			//cout<<s[i]<<" "<<s1[i]<<" "<<"saeraf"<<endl;
			if(s[i]>s1[i])
			{
				//cout<<s[i]<<" "<<s1[i]<<endl;
				y=0;
				f(j,i+1,sz(s))
				{
					//cout<<"sarraf"<<endl;
					if(s1[i]>=s[j])
					{
						//cout<<"sarraf1"<<endl;
						temp1=s[j];
						s[j]=s[i];
						s[i]=temp1;
						x=1;
						y=1;
						break;
					}
				}
				if(x==0 && y==0)
				{
					//cout<<"---"<<endl;
					break;
				}
			}
			else if(s[i]<s1[i])
			{
				x=1;
				break;
			}
			else
			{
				//cout<<"sarradf";
				if(i==sz(s)-1)
				{	//cout<<"ji";
					x=1;
				}
			}
			if(x==1)
				break;
		}
		//cout<<s<<" "<<s1<<endl;
		f(i,0,sz(s))
		{
			if(s1[i]<s[i])
			{
				x=0;
				break;
			}
			else if(s1[i]>s[i])
			{
				x=1;
				break;
			}
		}
		if(x==1)
			cout<<s<<endl;
		else
		{
			cout<<"---"<<endl;
			x=0;
		}
	}

}


/*input
3
TTT TTTTTTTTTT
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ll n;
	cin>>n;
	string s,s1;char t;
	f(k,0,n)
	{
		cin>>s>>s1;
		f(i,0,sz(s))
		{
			if(s[i]<s1[i])
			{
				cout<<s<<endl;
				break;
			}
			else if(s[i]==s1[i] && sz(s1)<sz(s) && i==sz(s1)-1)
			{
				cout<<"---"<<endl;
			}
			else if(s[i]==s1[i] && i==sz(s)-1)
			{
				cout<<s<<endl;
			}
			else if(s[i]==s1[i])
			{
				//cout<<s[i]<<endl;
				continue;
			}
			else
			{
				if(i==sz(s)-1)
					cout<<"---"<<endl;
				f(j,i+1,sz(s))
				{
					//cout<<s[j]<<" "<<s1[i]<<endl;
					if(s[j]<=s1[i])
					{
						t=s[j];
						s[j]=s[i];
						s[i]=t;
						if(s<s1)
						{
							cout<<s<<endl;
						}
						else
							cout<<"---"<<endl;
						break;
					}
					else if(j==sz(s)-1)
					{
						cout<<"---"<<endl;
						break;
					}
				}
				break;
			}

		}
	}
}


/*input
3
AZAMON APPLE
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ll n;
	cin>>n;
	string s,s1;char t;
	f(k,0,n)
	{
		cin>>s>>s1;
		f(i,0,sz(s))
		{
			if(s[i]<s1[i])
			{
				cout<<s<<endl;
				break;
			}
			else if(s[i]==s1[i] && sz(s1)<sz(s) && i==sz(s1))
			{
				cout<<"---"<<endl;
			}
			else if(s[i]==s1[i] && i==sz(s))
			{
				cout<<s<<endl;
			}
			else if(s[i]==s1[i])
			{
				//cout<<s[i]<<endl;
				continue;
			}
			else
			{
				f(j,i+1,sz(s))
				{
					//cout<<s[j]<<" "<<s1[i]<<endl;
					if(s[j]<=s1[i])
					{
						t=s[j];
						s[j]=s[i];
						s[i]=t;
						if(s<s1)
						{
							cout<<s<<endl;
						}
						else
							cout<<"---"<<endl;
						break;
					}
					else if(j==sz(s))
					{
						cout<<"---";
						break;
					}
				}
				break;
			}

		}
	}
}


/*input
3
AZAMON APPLE
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll n;
	cin>>n;
	string s,s1,s2;char temp1;ll x=0;
	f(k,0,n)
	{
		cin>>s>>s1;x=0;
		//cout<<s<<" "<<s1<<endl;
		f(i,0,sz(s))
		{
			//cout<<s[i]<<" "<<s1[i]<<" "<<sz(s)<<endl;
			if(s[i]>s1[i])
			{
				//cout<<s1[i]<<" "<<s[i]<<endl;
				f(j,i+1,sz(s))
				{
					if(s1[i]>s[j])
					{
						temp1=s[j];
						s[j]=s[i];
						s[i]=temp1;
						x=1;
						break;
					}
				}
			}
			else if(s[i]<s1[i])
			{
				x=1;
				break;
			}
			if(x==1)
				break;
		}
		if(x==1)
			cout<<s<<endl;
		else
		{
			cout<<"..."<<endl;
			x=0;
		}
	}

}


/*input
1
TTT TTTTTTT

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<ll int,ll int>
#define mis         map<ll int, string>
#define f(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int> >
#define mip         map<ll int,vii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	ll n;
	cin>>n;
	string s,s1,s2;char temp1;ll x=0;
	f(k,0,n)
	{
		cin>>s>>s1;x=0;ll y=0;
		//cout<<s<<" "<<s1<<endl;
		f(i,0,sz(s))
		{
			//cout<<s[i]<<" "<<s1[i]<<" "<<"saeraf"<<endl;
			if(s[i]>s1[i])
			{
				//cout<<s[i]<<" "<<s1[i]<<endl;
				y=0;
				f(j,i+1,sz(s))
				{
					//cout<<"sarraf"<<endl;
					if(s1[i]>s[j])
					{
						//cout<<"sarraf1"<<endl;
						temp1=s[j];
						s[j]=s[i];
						s[i]=temp1;
						x=1;
						y=1;
						break;
					}
				}
				if(x==0 && y==0)
				{
					//cout<<"---"<<endl;
					break;
				}
			}
			else if(s[i]<s1[i])
			{
				x=1;
				break;
			}
			else
			{
				//cout<<"sarradf";
				if(i==sz(s)-1)
				{	//cout<<"ji";
					x=1;
				}
			}
			if(x==1)
				break;
		}
		if(x==1)
			cout<<s<<endl;
		else
		{
			cout<<"---"<<endl;
			x=0;
		}
	}

}


#include<bits/stdc++.h>
using namespace std;
int PC[30005][25],MLEmin;
void UKEtoPC (string UKE,int TLE){
	int MLE=UKE.size();
	MLEmin=min(MLEmin,MLE);
	for(int RE=1;RE<MLE;RE++)
		PC[TLE][RE]=UKE[RE-1]-'0';
}
int main(){
	int WA,AC;
	string UKE;
	cin>>WA;
	for(int TLE=1;TLE<=WA;TLE++){
		cin>>UKE;
		UKEtoPC(UKE,TLE);
	}
	for(AC=1;AC<=MLEmin;AC++){
		int RP=PC[1][AC];
		bool AK=1;
		for(int TLE=2;TLE<=WA&&AK;TLE++)
			if(PC[TLE][AC]==RP)
				continue;
			else
				AK=0;
		if(AK)
			continue;
		else

			break;
	}
	cout<<AC-1<<endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
string st[1000];
int main(){
	int i,j,k,n,sum=0;
	cin>>n;
	for(i=1;i<=n;i++)cin>>st[i];
	for(j=0;j<st[1].length();j++){
		k=0;
	    for(i=1;i<n;i++){
	        if(st[i][j]!=st[i+1][j])k++;
	    }
	    if(k==0)sum++;
	    else{
	    	cout<<sum<<endl;
	    	return 0;
		}
	}
}


#include <iostream>
#include <string>
using namespace std;
string st[30001];
int main(){
	int i,j,k,n,sum=0;
	cin>>n;
	for(i=1;i<=n;i++)cin>>st[i];
	for(j=0;j<st[1].length();j++){
	    for(i=1;i<n;i++){
	        if(st[i][j]!=st[i+1][j]){
			    cout<<sum<<endl;
			    return 0;
	        }
	    }
	    sum++;
	}
	cout<<sum<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
int main()
{
	int n, t = 0, min = 2147483647;
	std::string x[3001];
	scanf("%d",&n);
	for(int i = 0;i < n;i++) std::cin >> x[i];
	for(int i = 0;i < n;i++) if(x[i].size() < min) min = i;
	for(int i = 0;i < x[min].size();i++)
	{
		for(int j = 1;j < n;j++)
			if(x[j][i] != x[1][i])
			{
				printf("%d",t);
				return 0;
			}
		t++;
	}
	printf("%d",t);
	return 0;
}


#include<cstring>
#include<cstdio>
using namespace std;
int n,len;
char a[100005][105],cmp1[105],cmp2[105];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%s",&a[i]);
		if(!i)
		len=strlen(a[0]);
		for(int j=0;j<len;j++)
		cmp1[j]+=a[i][j];
	}
	for(int i=0;i<len;i++)
	cmp2[i]=a[0][i]*n;
	for(int i=0;i<len;i++)
	if(cmp1[i]!=cmp2[i])
	{
		printf("%d",i);
		return 0;
	}
	printf("%d",len);
	return 0;
}


#include<bits/stdc++.h>
int n,len;
char a[100005][105],cmp1[105],cmp2[105];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",&a[i]);
		if(!i)
		len=strlen(a[0]);
		for(int j=0;j<len;j++)
		cmp1[j]+=a[i][j];
	}
	for(int i=0;i<len;i++)
	cmp2[i]=a[0][i]*n;
	for(int i=0;i<len;i++)
	if(cmp1[i]!=cmp2[i]){
		printf("%d",i);
		return 0;
	}
	printf("%d",len);
}


#include<bits/stdc++.h>//ddddddddddddddddddddddddddddddddddddddd
using namespace std;
int main()
{
    bool cmp=false;
    string s[30001];
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>s[i];
    for(int i=0;i<s[0].length();i++)
    {
        for(int j=2;j<=n;j++)
        {
            if(s[j][i]!=s[j-1][i]) cmp=true;
        }
        if(cmp==true) break;
        else ans++;
    }
    cout<<ans<<endl;
}


#include<iostream>
#include<cstring>
using namespace std;
string a,b,c;
long long n,k;
int main()
{
    cin>>n>>b;//输入数量和第一个
    for(int s=1;s<n;s++)
    {
        cin>>a;
        c="";
        k=min(a.size(),b.size());
        for(int v=0;v<k;v++)//寻找最长前缀
        {
            if(b[v]==a[v])
            c=c+b[v];
            else break;//不相同跳出
        }
        b=c;
    }
    cout<<b.size()<<endl;//输出它的长度
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,ans=0;
	scanf("%d",&n);
	string a[30001];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<a[0].size();i++)
	{
		for(int j=0;j<n;j++)
		{
			if(j==0) x=a[j][i];
			else if(a[j][i]!=x)
			{
				printf("%d",ans);
				return 0;
			}
		}
		ans++;
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
string T1,a,b,c;
long long n,ans,sum;
int main(){
    cin>>n;
    cin>>T1;
    for(int i=1;i<=n;i++){
        cin>>a;
        c=" ";
        ans=min(a.size(),b.size());
        for(int j=0;j<ans;j++){
            if(b[j] == a[j]){
              c=c+b[j];
            }
            else break;
        }
        b=c;
    }
    cout<<c.size();
    return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n;
	string s[30001];
	cin>>n;
	for(int i=1; i<=n; i++) cin>>s[i];
	char now;
	int ans=0;
	while(1)
	{
		now=s[1][ans];
		for(int i=2; i<=n; i++)
		{
			if(s[i][ans]!=now)
			{
				cout<<ans<<endl;
				return 0;
			}
		}
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string a,b,c;
long long n,k;
int main()
{
    cin>>n>>b;
    for(int s=1;s<n;s++)
    {
        cin>>a,c="";
        k=min(a.size(),b.size());
        for(int v=0;v<k;v++)
            if(b[v]==a[v])c=c+b[v];
            else break;
        b=c;
    }
    cout<<b.size()<<endl,exit(0);
}


#include <bits/stdc++.h>
#include <queue>
#include <set>
#include <vector>
#include <deque>

#define lowbit(x) x & -x

#pragma GCC optimize(3)

using namespace std;

template <class T> inline void read(register T &x)
{
    register long long flag = 1;
    x = 0; register char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') flag = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    x *= flag; return;
}

template <class T, typename... Args>
inline void read(register T &opt, Args&... args) {
    read(opt); read(args...);
}

template <class T> inline void write(register T x)
{
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

template <class T> inline void writeln(register T x)
{
    write(x);
    puts("");
}

template <class T> inline void writeln(register T x, char c)
{
    write(x); putchar(c);
}

template <class T> inline void chkmax(T &X, const T Y)
{
    X > Y ? X = X : X = Y;
}

template <class T> inline void chkmin(T &X, const T Y)
{
    X < Y ? X = X : X = Y;
}

typedef long long ll;

int n, k = 0, slen = 25; string str[300005];

inline void readstr(string &S) {
	S.clear();
	register char ch = getchar();
	while (ch != ' ' && ch != '\n') {
		S.push_back(ch); ch = getchar();
	}
}

int main(void)
{
	read(n);
	for (register int i = 1; i <= n; i++)
		cin >> str[i], chkmin(slen, (int)str[i].size());

	for (register int i = 1; i <= slen; i++) {
		for (register int j = 2; j <= n; ++j)
			if (str[j][i] != str[j - 1][i]) {
				writeln(i); return 0;
			}
		++k;
	}

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
int main()
{
	int n, t = 0, min = 2147483647;
	std::string x[3001];
	scanf("%d",&n);
	for(int i = 0;i < n;i++)
	{
		std::cin >> x[i];
		if(x[i].size() < min) min = x[i].size();
	}
	for(int i = 0;i < min;i++)
	{
		for(int j = 1;j < n;j++)
			if(x[j][i] != x[0][i])
			{
				printf("%d",t);
				return 0;
			}
		t++;
	}
	printf("%d",t);
	return 0;
}


#include<iostream>
using namespace std;
int n,l;string s,st;
int main()
{
	cin>>n>>st;l=st.size();
    for(int i=2;i<=n;i++)
	{
		cin>>s;
        for(int j=0;j<l;j++)
			if(s[j]!=st[j]){l=j;break;}
    }
    cout<<l<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,s;
char a[30001][21];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<=20;i++)
	{
		int k=0;
		for(int o=2;o<=n;o++)
		{
			if(a[o][i]==a[o-1][i])
			{

			}
			else
			{
				k=0;
				break;
			}
		}
		if(k==0)
		{
			s++;
		}
		else
		{
			break;
		}
	}
	cout<<s;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
using namespace std;
char a[30005][25];
int main()
{int n;
 cin>>n;
 for(int i=0;i<n;i++)
   cin>>a[i];
 int s=0,chang=strlen(a[0]);
 for(int i=0;i<chang;i++){
   bool t=0;
   char k=a[0][i];
   for(int j=0;j<n;j++){
     if(k!=a[j][i]) t=1;
     if(t==0) s++;
       else break;
   }
 }
 cout<<s<<endl;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,c=0,d=0;
	scanf("%d",&a);
	char b[a][20];
	for(int i=0;i<a;i++){
		scanf("%s",b[i]);
	}
	for(int i=0;i<20;i++){
		for(int j=0;j<a-1;j++){
			if(b[j][i]!=b[j+1][i]){
				printf("%d",c);
				return 0;
			}
		}
		c++;
	}
	printf("%d",c);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string a,b,c;
long long n,k;
int main(){
    cin>>n>>b;
    for(int i=1;i<n;i++){
        cin>>a;
        c="";
        k=min(a.size(),b.size());
        for(int j=0;j<k;j++){
            if(b[j]==a[j]){
            	c=c+b[j];
			}else{
            	break;
			}
        }
        b=c;
    }
    cout<<b.size()<<endl;
    return 0;
}


#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;
int a[40000][21];
string s;
int main(){
	int l,n,m,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s;
		l=s.size();
		for(int j=0;j<l;j++)
			a[i][j+1]=int(s[j]-'0');
	}
	for(int i=1;i<=l;i++){
		int t=a[1][i];
		for(int j=2;j<=n;j++)
			if(a[j][i]!=t){
				cout<<sum;
				return 0;
			}
		sum++;
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,ansk;
	cin>>n;
	char maps[100005];
	char ans[100005];
	cin>>maps;
	ansk = strlen(maps);
	for(int i=1;i<=ansk;i++){
		ans[i] = maps[i-1];
	}
	for(int i=2;i<=n;i++){
		cin>>maps;
		for(int j=1;j<=ansk;j++){
			if(maps[j-1]!=ans[j]){
				ansk = j;
				break;
			}
		}
	}
	ansk--;
	if(ansk==0) cout<<0<<endl;
	else{
		cout<<ansk<<endl;
	}

}


#include<iostream>

using namespace std;

int main(){
    int n,x=0;
    bool bx=true;
    cin>>n;
    char arr[n][20];
    for (int i=0; i<n; i++)
            cin>>arr[i];
    for (int i=0; arr[0][i]!='\0'; ++i)
    {
        for (int j=0; j<n-1; j++)
            if (arr[j][i] != arr[j+1][i])
            {
                bx=false;
                break;
            }
        if(bx)
            x++;
    }
    cout<<x;
    return 0;
}


#include<iostream>

using namespace std;

int main(){
    int n,x=0;
    bool bx=true;
    cin>>n;
    char arr[n][21];
    for (int i=0; i<n; i++)
            cin>>arr[i];
    for (int i=0; arr[0][i]!='\0'; ++i)
    {
        for (int j=0; j<n-1; j++)
            if (arr[j][i] != arr[j+1][i])
            {
                bx=false;
                break;
            }
        if(bx)
            x++;
    }
    cout<<x;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string a[30010];
int ans,l,n;
int main()
{
    cin>>n;
    for(register int i=0;i<n;i++) cin>>a[i];
    l=a[0].size();
    for(register int i=0;i<l;i++) for(register int j=1;j<n;j++)
    if(a[j][i]!=a[j-1][i])
    {
        cout<<i;
        return 0;
    }
    cout<<l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string a[30010];
int ans,l;
int main()
{
    cin>>n;
    for(register int i=0;i<n;i++) cin>>a[i];
    l=a[i].size();
    for(register int i=0;i<l;i++) for(register int j=1;j<n;j++)
    if(a[j][i]!=a[j-1][i])
    {
        cout<<i;
        return 0;
    }
    cout<<l;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string a[30010];
int ans,l;
int main()
{
    cin>>n;
    for(register int i=0;i<n;i++) cin>>a[i];
    l=a[0].size();
    for(register int i=0;i<l;i++) for(register int j=1;j<n;j++)
    if(a[j][i]!=a[j-1][i])
    {
        cout<<i;
        return 0;
    }
    cout<<l;
    return 0;
}


#include<iostream>

using namespace std;

string s[1000000];
int n;
bool isSame=true;

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
    }

    int lo=0;
    while(lo<s[0].size() && (isSame)){
        int i=0;
        while ((isSame) && i<n-1){

            if(s[i][lo]!=s[i+1][lo]){
                isSame=false;
            }
            else{
                i++;
            }
        }
        if(isSame){
            lo++;
        }
    }

    cout<<lo;
}


int main()
{
    int n, counter = 0;
    vector<string> x;
    string temp;
    bool flag = false, flag2 = false;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        x.push_back(temp);
    }

    for(int i = 0; i < x[0].length();i++)
    {
        for(int j = 0; j < n - 1; j++)
        {
            if(x[j].at(i) == x[j+1].at(i))
                flag2= true;
            else {flag = true;
            flag2 = false;
            break;
            }
        }
        if (flag2){
            counter++;
            flag2 = false;
        }
        if (flag)
            break;
    }

    cout << counter;
    return 0;
}


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

int main()
{
    int n, counter = 0;
    vector<string> x;
    string temp;
    bool flag = false, flag2 = false;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> temp;
        x.push_back(temp);
    }

    for(int i = 0; i < x[0].length();i++)
    {
        for(int j = 0; j < n - 1; j++)
        {
            if(x[j].at(i) == x[j+1].at(i))
                flag2= true;
            else {flag = true;
            flag2 = false;
            break;
            }
        }
        if (flag2){
            counter++;
            flag2 = false;
        }
        if (flag)
            break;
    }

    cout << counter;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,d=0;
    cin>>n;
    string s[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    int h=-9999;
    for(int i=0;i<s[1].size();i++)
    {
        for(int j=1;j<n;j++)
        {
            if(s[j][i]!=s[j+1][i])
                {
                    h=max(h,d);
                    d=0;
                    break;
                }
            if(j==(n-1))
                {
                    d++;
                }
        }
    }
    cout<<h;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    int d=0;
    cin>>n;
    string s[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    int h=-9999;
    for(int i=0;i<s[1].size();i++)
    {
        for(int j=1;j<n;j++)
        {
            if(s[j][i]!=s[j+1][i])
                {
                    h=max(h,d);
                    d=0;
                    break;
                }
            if(j==(n-1))
                {
                    d++;
                }
        }
    }
    if(h==1)
    {
        cout<<0;
        return 0;
    }
    cout<<h;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    int d=0;
    cin>>n;
    string s[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    int h=-9999;
    for(int i=0;i<s[1].size();i++)
    {
        for(int j=1;j<n;j++)
        {
            if(s[j][i]!=s[j+1][i])
                {
                    h=max(h,d);
                    d=0;
                    break;
                }
            if(j==(n-1))
                {
                    d++;
                }
        }
    }
    cout<<h;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    int d=0;
    cin>>n;
    string s[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    int h=-9999;
    for(int i=0;i<s[1].size();i++)
    {
        for(int j=1;j<n;j++)
        {
            if(s[j][i]!=s[j+1][i])
                {
                    h=max(h,d);
                    d=0;
                    break;
                }
            if(j==(n-1))
                {
                    d++;
                }
        }
    }
    if(h==1 && n==2)
    {
        cout<<0;
        return 0;
    }
    cout<<h;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main ()
{
	int k;
	cin >> k;
	string a[k + 4];
	for (int i = 0; i < k; i++)
		cin >> a[i];
	for (int i = 0; i < a[0].size(); i++)
		for (int j = 0; j < k - 1; j++)
			if (a[j][i] != a[j + 1][i])
			{
				cout << i;
				return 0;
			}
	cout << a[0].size();
	return 0;
}


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

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	string s[30001], a;
	int lenma = 21;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		int len = s[i].size();
		lenma = lenma > len ? len : lenma;
	}
	int ans = 0;
	for (int i = 0; i < lenma; i++) {
		int num = 0;
		for (int k = 0; k < n - 1; k++) {
			if (s[k][i] != s[k + 1][i]) {
				num++;
			}
		}
		if (num == 0) {
			ans++;
		}
		else {
			cout << ans;
			return 0;
		}
	}
	cout << lenma;
	return 0;
}
//2


#include<bits/stdc++.h>
using namespace std;
char d[30001][21];
int main()
{
    int a,minn=0x7ffffff;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
    cin>>d[i];
    if(strlen(d[i])<minn)
    minn=strlen(d[i]);
    for(int i=0;i<=minn-1;i++)
    {
        char y=d[1][i];
        for(int j=2;j<=a;j++)
        {
            if(d[j][i]!=y)
            {
                cout<<i;
                return 0;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
char d[30001][21];
int main()
{
    int a,minn=0x7ffffff;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
    cin>>d[i];
    if(strlen(d[i])<minn)
    minn=strlen(d[i]);
    }
    for(int i=0;i<=minn-1;i++)
    {
        char y=d[1][i];
        for(int j=2;j<=a;j++)
        {
            if(d[j][i]!=y)
            {
                cout<<i;
                return 0;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
char d[30001][21];
int main()
{
    int a,minn=0x7ffffff;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
    cin>>d[i];
    if(strlen(d[i])<minn)
    minn=strlen(d[i]);
    for(int i=0;i<=minn-1;i++)
    {
        char y=d[1][i];
        for(int j=2;j<=a;j++)
        {
            if(d[j][i]!=y)
            {
                cout<<i;
                return 0;
            }
        }
    }
}}


#include <iostream>
#include <string>
using namespace std;
int main() {
    int n = 0;
    string arr[3000];
    int largest = 200, count = 0, j = 0;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin>>arr[i];
    }
    for (int i = 1; i < n; i++) {
        j = 0;
        count = 0;
        while (j < arr[0].length()) {
            if (arr[i][j] == arr[0][j]) {
                count++;
                j++;
            } else {
                break;
            }
        }
        if (count < largest) {
            largest = count;
        }
    }
    cout<<largest<<endl;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main() {
    int n = 0;
    string arr[30010];
    int largest = 200, count = 0, j = 0;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin>>arr[i];
    }
    for (int i = 1; i < n; i++) {
        j = 0;
        count = 0;
        while (j < arr[0].length()) {
            if (arr[i][j] == arr[0][j]) {
                count++;
                j++;
            } else {
                break;
            }
        }
        if (count < largest) {
            largest = count;
        }
    }
    cout<<largest<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int N=3e4+10;
string s[N];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>s[i];
    int len=s[1].size(),flag=0;
    for(int i=0;i<len;i++)
    {
        for(int j=2;j<=n;j++)
        {
            if(s[1][i]!=s[j][i])
            {
                cout<<i<<endl;
                flag=1;
                break;
            }
        }
        if(flag) break;
    }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include<sstream>
#include <iomanip>
const double pi = acos(-1.0);
using namespace::std;

int main(int argv, char** args)
{

	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	char curr = s[0][0];
	int res = 0;
	for (int j = 0; j < s[0].length(); j++)
	{
		curr = s[0][j];
		int temp = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i][j] == curr)
			{
				temp++;
			}
		}
		if (temp == n)
			res++;
		else
			break;
	}
	cout << res;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include<sstream>
#include <iomanip>
const double pi = acos(-1.0);
using namespace::std;

int main(int argv, char** args)
{

	int n;
	cin >> n;
	vector<string> s(n);
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
	}
	char curr = s[0][0];
	int res = 0;
	for (int j = 0; j < s[0].length(); j++)
	{
		curr = s[0][j];
		int temp = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i][j] == curr)
			{
				temp++;
			}
		}
		if (temp == n)
			res++;
	}
	cout << res;
}


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

int main() {
	int n;
	cin >> n;
	string x;
	getline (cin , x);
	getline (cin , x);
	int c=x.length();
	deque <char> y;
	char u;
	for(int i=0;i<c;i++){
	y.push_back(x.at(i));
	}
	n--;
	int e=0;
	c=y.size();

		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				e++;
			}
		}
		if(e>=1)
		for(int i=0;i<e;i++){
		y.pop_back();
		}
		e=0;
	while(n--){
		x="";
		getline (cin , x);
		c=y.size();
		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				e++;
			}
		}
		if(e>=1)
		for(int i=0;i<e;i++)
		y.pop_back();
		e=0;
	}
	c=y.size();
	cout << c;
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	string x;
	getline (cin , x);
	getline (cin , x);
	int c=x.length();
	deque <char> y;
	char u;
	for(int i=0;i<c;i++){
	y.push_back(x.at(i));
	}
	n--;
	int e=0;
	c=y.size();
		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				e++;
			}
		}
		if(e>=1)
		for(int i=0;i<e;i++){
		y.pop_back();
		}
		e=0;
	while(n--){
		x="";
		getline (cin , x);
		c=y.size();
		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				e++;
			}
		}
		if(e>=1)
		for(int i=0;i<e;i++)
		y.pop_back();
		e=0;
	}
	c=y.size();
	cout << c;
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	string x;
	getline (cin , x);
	getline (cin , x);
	int c=x.length();
	deque <char> y;
	char u;
	char t;
	for(int i=0;i<c;i++){
	y.push_back(x.at(i));
	}
	n--;
	int e=0;
	c=y.size();

		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				y.erase(y.begin()+i,y.begin()+c);
			}
		}
		if(e>=1)
		for(int i=0;i<e;i++){
		y.pop_back();
		}
		e=0;
	while(n--){
		x="";
		getline (cin , x);
		c=y.size();
		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				y.erase(y.begin()+i,y.begin()+c);
				break;
			}
		}
	}
	c=y.size();
	cout << c;
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	string x;
	getline (cin , x);
	getline (cin , x);
	int c=x.length();
	deque <char> y;
	char u;
	char t;
	for(int i=0;i<c;i++){
	y.push_back(x.at(i));
	}
	n--;
	int e=0;
	c=y.size();
		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				y.erase(y.begin()+i,y.begin()+c);
			}
		}
		if(e>=1)
		for(int i=0;i<e;i++){
		y.pop_back();
		}
		e=0;
	while(n--){
		x="";
		getline (cin , x);
		c=y.size();
		for(int i=0;i<c;i++){
			if(x.at(i)!=y[i]){
				y.erase(y.begin()+i,y.begin()+c);
				break;
			}
		}
	}
	c=y.size();
	cout << c;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,cnt,mn = 30;
char s[30005][21];

int main() {
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    scanf("%s",s[i]);
    mn = min(mn,(int)strlen(s[i]));
  }
  for (int i = 0; i < mn; i++) {
    bitset<10> mark(0);
    for (int j = 0; j < n; j++) {
      mark[s[j][i] - '0'] = true;
    }
    if (mark.count() > 1) {
      break;
    } else {
      cnt++;
    }
  }
  printf("%d",cnt);
}


#include <bits/stdc++.h>

using namespace std;

int n,cnt,mn = 30;
char s[3005][21];

int main() {
  scanf("%d",&n);
  for (int i = 0; i < n; i++) {
    scanf("%s",s[i]);
    mn = min(mn,(int)strlen(s[i]));
  }
  for (int i = 0; i < mn; i++) {
    bitset<10> mark(0);
    for (int j = 0; j < n; j++) {
      mark[s[j][i] - '0'] = true;
    }
    if (mark.count() > 1) {
      break;
    } else {
      cnt++;
    }
  }
  printf("%d",cnt);
}


#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
#define int long long
#define ij i=0,j=0;
void print(int a)                  {              cout<<a<<'\t'<<'\n';}
void print(int a,int b)                {          cout<<a<<'\t'<<b<<'\t'<<'\n';}
void print(int a,int b,int  c)             {      cout<<a<<'\t'<<b<<'\t'<<c<<'\n';}
void print(int a,int  b,int  c,int  d)         {   cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\n';}
void print(int a,int  b,int  c,int  d,int  e)      { cout<<a<<'\t'<<b<<'\t'<<c<<'\t'<<d<<'\t'<<e<<'\n';}

/// # day 2
// 3 8 20  - 12

void MAIN()
{
    int n;  cin>>n;
    vector<string> a(n);

    for(auto &i:a)
        cin>>i;
    for(int i=0 ; i<a[0].length() ; i++)
    {
        for(int j=1; j<n ; j++)
        {
            if(a[j][i] != a[j-1][i] )
            {
                cout<<i;
                return ;
            }
        }
    }
    cout<<a[0].length();
}

int32_t main()
{
 // ios_base::sync_with_stdio(0) , cin.tie(0),cout.tie(0);  int t;  cin>>t; while(t--)
    MAIN();
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<cstdio>
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ; i ++)
#define All(X)  (X).begin(),X.end()
using namespace std;

vector<int> Solv;
int main()
{
    int N;sfi(N);
    vector<string> Vec(N);
    lop(i, N)cin >> Vec[i];
    int i;

    for ( i = 1; i <= Vec[0].size();i++)
    {
        string Keeper = Vec[0].substr(0,i);
        for (int j = 0; j < Vec.size();j++)
        {
            if (Vec[j].substr(0,i) != Keeper)
            {

                    cout << i-1  << endl;

                //system("pause");
                return 0;
            }

        }
    }

//system("pause");
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include<set>
#include <cmath>
#include<sstream>
#include<vector>
#include<stdio.h>
#include<stack>
#include<deque>
#include<cstdio>
#define prfi(x) printf("%d\n",x);
#define sfi(X) scanf("%d",&X);
#define lop(i,n) for (int i = 0 ; i < n ; i ++)
#define All(X)  (X).begin(),X.end()
using namespace std;

vector<int> Solv;
int main()
{
    int N;sfi(N);
    vector<string> Vec(N);
    lop(i, N)cin >> Vec[i];
    int i;

    for ( i = 1; i < Vec[0].size();i++)
    {
        string Keeper = Vec[0].substr(0,i);
        for (int j = 0; j < Vec.size();j++)
        {
            if (Vec[j].substr(0,i) != Keeper)
            {
                if (Vec[j].size()>1)
                    cout << i-1  << endl;
                else
                    cout << 0 << endl;
                //system("pause");
                return 0;
            }

        }
    }

//system("pause");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s[n+1];
	int x,cnt,i;
	cnt=2147480000;
	for (i=1;i<=n;i++)
	{
		cin>>s[i];
		x=s[i].size();
		cnt=min(cnt,x);
	}
	bool flag;
	flag=true;
	x=0;
	for (i=0;i<=cnt;i++)
	{
		for (int j=1;j<=n-1;j++)
		{
			if (s[j][i]!=s[j+1][i])
			{
				flag=false;
			}
		}
		if (flag==true)
		{
			x++;
		}
	}
	cout<<x<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string s[n];
	int x,cnt,i;
	cnt=2147480000;
	for (i=1;i<=n;i++)
	{
		cin>>s[i];
		x=s[i].size();
		cnt=min(cnt,x);
	}
	bool flag;
	flag=true;
	x=0;
	for (i=0;i<=cnt;i++)
	{
		for (int j=1;j<=n-1;j++)
		{
			if (s[j][i]!=s[j+1][i])
			{
				flag=false;
			}
		}
		if (flag==true)
		{
			x++;
		}
	}
	cout<<x<<endl;
	return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <strings.h>
#include <cstring>

using namespace std;
bool ceksubstr(string c[], int sub, int n)
{
    bool valid=true;
    int i=0;
    while (i<n&&valid)
    {
        if(c[i].substr(sub,1)!=c[0].substr(sub,1)) //c[0] is just a sample...
        {
            valid=false;
        }
        i++;
    }
    return valid;
}
int main()
{
    int n,digit=0,iter=0;
    cin>>n;
    string contact[n];
    for(int i=0;i<n;i++)
    {
        cin>>contact[i];
    }
    bool cont=true;
    while(iter<n&&cont)
    {
        if(ceksubstr(contact,iter,n))
        {
            digit++;
        }
        else{cont=false;}
        iter++;
    }
    cout<<digit<<endl;
    return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <strings.h>
#include <cstring>

using namespace std;
bool ceksubstr(string c[], int sub, int n)
{
    bool valid=true;
    int i=0;
    while (i<n&&valid)
    {
        if(c[i].substr(sub,1)!=c[0].substr(sub,1)) //c[0] is just a sample...
        {
            valid=false;
        }
        i++;
    }
    return valid;
}
int main()
{
    int n,digit=0,iter=0;
    cin>>n;
    string contact[n];
    for(int i=0;i<n;i++)
    {
        cin>>contact[i];
    }
    bool cont=true;
    while(iter<contact[0].length()&&cont)
    {
        if(ceksubstr(contact,iter,n))
        {
            digit++;
        }
        else{cont=false;}
        iter++;
    }
    cout<<digit<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string solve(string a,string b){
    string ans = "";
    int cnt = 0;
    while(a[cnt] == b[cnt] and cnt < a.size() and cnt < b.size()){
        ans += a[cnt];
        cnt++;
    }
    return ans;
}
string a[123123];
int n;
int main(){
//    freopen("in.txt","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    string ans = solve(a[1],a[2]);
    for(int i=2;i<=n;i++){
        ans = solve(ans,solve(a[i],a[i-1]));
    }
    while(ans[ans.size()-1] == ' '){
        ans.erase(ans.size() - 1);
    }
    cout<<ans.size();
}


#include<bits/stdc++.h>
using namespace std;
string solve(string a,string b){
    string ans = "";
    int cnt = 0;
    while(a[cnt] == b[cnt] and cnt < a.size() and cnt < b.size()){
        ans += a[cnt];
        cnt++;
    }
    return ans;
}
string a[123123];
int n;
int main(){
    freopen("in.txt","r",stdin);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    string ans = solve(a[1],a[2]);
    for(int i=2;i<=n;i++){
        ans = solve(ans,solve(a[i],a[i-1]));
    }
    while(ans[ans.size()-1] == ' '){
        ans.erase(ans.size() - 1);
    }
    cout<<ans.size();
}


// In the name of Allah //
#include <bits/stdc++.h>
using namespace std;

string s[100005];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    int ans = s[0].size();
    for (int j = 1; j < n; j++) {
        int cnt = 0;
        for (int k = 0; k < s[j].size(); k++) {
            if(s[0][k] == s[j][k])
                cnt++;
            else
                break;
        }
        ans = min(ans, cnt);
    }
    cout << ans << "\n";
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char a[10010][21];
int main() {
	int n;
	cin >> n;
	int at = 1e9;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++) {
		int j = 0,tmp=0;
		while (a[i - 1][j] == a[i][j]) {
			tmp++;
			j++;
		}
		at = min(at,tmp);
	}
	cout << at << endl;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char a[50010][21];
int main() {
	int n;
	cin >> n;
	int at = 1e9;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++) {
		int j = 0,tmp=0;
		while (a[i - 1][j] == a[i][j]) {
			tmp++;
			j++;
		}
		at = min(at,tmp);
	}
	cout << at << endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <numeric>

using namespace std;

typedef long long ll;
typedef long double ld;

#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define file_name(a) (freopen(((string)(a) + ".in").c_str(),"r",stdin), freopen(((string)(a) + ".out").c_str(),"w",stdout))
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int nxt() {
	int x;
	cin >> x;
	return x;
}

int main() {
	int n = nxt();
	vector <string> a(n);
	forn(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	bool flag = true;
	while (flag) {
		forn(i, n) {
			if (a[i][ans] != a[0][ans]) {
				flag = false;
			}
		}
		ans++;
	}
	cout << ans - 1 << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
char a[100001][21];
int main() {
	int cont=0;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	int l=strlen(a[0]);
	if (l==1) {
		cout << 0;
		return 0;
	}
	int min=21;
	for (int i=0; i<n-1; i++) {
		cont =0;
		for (int j=0; j<l; j++) {
			if(a[i][j]==a[i+1][j]) {
				cont ++;
			}
			else {
				j=l;
			}
		}
		if(cont<min) {
			min=cont;
		}
	}
	cout << min;

	return 0;
}


#include<iostream>

using namespace std;

int main() {
    long long n, m=0;
    cin >> n;
    for(int i=1;i<n;i++) {
        m+=i;
    }
    if(n==1) {
        cout<<1;
        return 0;
    }
    long long y=(2*n+(n-2))*(2*n+(n-1));
    y=y/2;
    cout<<y+3*m;

}


#include <bits/stdc++.h>

using namespace std;

int n;
char a[100001][21];
int main() {
	int cont=0;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	int l=strlen(a[0]);
	if (l==1) {
		cout << 0;
		return 0;
	}
	int min=21;
	for (int i=0; i<n-1; i++) {
		for (int j=0; j<n; j++) {
			if(a[i][j]==a[i+1][j]) {
				cont ++;
			}
		}
		if(cont<min) {
			min=cont;
		}
		cont =0;
	}
	cout << min;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n;
char a[100001][21];
int main() {
	int cont=0;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	int min=21;
	for (int i=0; i<n-1; i++) {
		for (int j=0; j<n; j++) {
			if(a[i][j]==a[i+1][j]) {
				cont ++;
			}
		}
		if(cont<min) {
			min=cont;
		}
		cont =0;
	}
	cout << min;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return
#define MP make_pair
#define pb push_back
using namespace std;
string s[30005];
signed main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>s[i];
	int ans=0;
	for(int i=0;i<sz(s[0]);i++){
		bool same=1;
		for(int j=1;j<n;j++){
			if(s[j][i]!=s[0][i]){
				same=0;
				break;
			}
		}
		if(!same) break;
		ans++;
	}
	cout<<ans;
	re 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}

ll countSum(ll x)
{
    ll res = 0;
    while (x != 0)
    {
        res += (x % 10);
        x /= 10;
    }
    return res;
}
int main()
{
    fast ;
    int n;
    cin >> n;
     string s [n+1];
    for(int i = 0 ;i<n;i++)
        cin >> s[i];
    int ans = 0;
    int ss =s[0].sz;
     for ( int i=0;i<ss;i++)
     {
         char ch = s[0][i];
         int cnt = 1;
         for ( int j=1;j<n;j++)
         {
             if(s[j][i]==ch) cnt++;
         }
         if(cnt==n)
            ans++;
         else
            break;
     }
     cout << ans <<endl;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s1;
    string s;
    string next;
    cin >> s;
    s1=s;
    n=n-1;
    int len = s.length();
    //cout << s1 << "\n";
    while(n--)
    {
        cin >> next;
        for(int i=len;i>0;i--)
        {
            //cout << next.substr(0,i) << " " << s1.substr(0,i) << "\n";
            if(next.substr(0,i)==s1.substr(0,i))
            {
                s1=s1.substr(0,i);
                break;
            }
        }
    }
    cout << s1.length();
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s1;
    string s;
    string next;
    cin >> s;
    s1=s;
    n=n-1;
    int flag=0;
    int len = s.length();
    //cout << s1 << "\n";
    while(n--)
    {
        flag=0;
        cin >> next;
        for(int i=len;i>0;i--)
        {
            if(next.substr(0,i)==s1.substr(0,i))
            {
                s1=s1.substr(0,i);
                flag=1;
                break;
            }
        }
    }
    if(flag)
        cout << s1.length();
    else
        cout << "0";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,i,j;
    int c=30000;
    scanf("%d",&x);
    string a[x];
    for(i=0;i<x;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<x-1;i++)
    {
        for(j=0;j<=c;j++)
        {
            if(a[i][j]!=a[i+1][j])
                {
                    if(j<=c)
                        c=j;
                    break;
                }
        }
    }
printf("%d",c);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,i,j;
    int c=30000;
    scanf("%d",&x);
    string a[x];
    for(i=0;i<x;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<x;i++)
    {
        int u=0;
        for(j=0;a[i][j]!='\0';i++)
        {
            if(a[i][j]==a[i+1][j])
                u++;
            else
                false;
        }
        if(u<=c)
            c=u;
    }
printf("%d",c);
}


#include <iostream>
#include <string>
using namespace std;
int n,ans;
string s,t;
int main()
{
  cin >> n >> s;
  ans = s.size();
  while(n--)
  {
    cin >> t;
    for(int i = 0;i < ans;i++)
      if(t[i] != s[i])
	ans = min(i,ans);
  }
  cout << ans;
  return 0;
}


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

int n,k;
main(){
    string f,s;

cin>>n>>f;
int p=f.size();
int ne=p;
while (--n) {cin>>s;
for (int i=p-1;i>=0;i--){
    if(f[i]!=s[i]) ne=i;
    p=ne;
}}
cout<<p;
}


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

int n,k;
main(){
    string f,s;

cin>>n>>f;
int p=f.size();
int ne=p;
while (--n) cin>>s;
for (int i=p-1;i>=0;i--){
    if(f[i]!=s[i]) ne=i;
    p=ne;
}
cout<<p;
}


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

int n,k;
main(){
    string f,s;

cin>>n>>f;
int p=f.size();
int ne=p;
while (--n) cin>>s;
for (int i=p-1;i>0;i--){
    if(f[i]!=s[i]) ne=i;
    p=ne;
}
cout<<p-1;
}


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

int n,k;
main(){
    string f,s;

cin>>n>>f;
int p=f.size();
int ne=p;
while (--n) cin>>s;
for (int i=p-1;i>0;i--){
    if(f[i]!=s[i]) ne=i;
    p=ne;
}
cout<<p;
}


//lxrtxdy!
#include<bits/stdc++.h>
using namespace std;
int n,pd,ans;
string s[30001];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>s[i];
	}
	for (int i=0;i<s[1].size();i++){
		for (int j=1;j<n;j++){
			if (s[j][i]!=s[j+1][i]){
				pd=1;break;
			}
		}
		if (pd==0) ans++;
		else break;
	}
	cout<<ans<<endl;
	return 0;
}
//orzlxr!//hello


#include<bits/stdc++.h>
using namespace std;
string st[30001];
int k,n,sum;
int main()
{
    scanf("%d",&n);
    getchar();
    for(int i=1;i<=n;i++)cin>>st[i];
    for(int j=0;j<st[1].size();j++,sum++)
        for(int i=1;i<n;i++)
            if(st[i][j]!=st[i+1][j]) return printf("%d",sum),0;
    printf("%d",sum);
	return 0;
}


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

int n;
int ans = 0;

string str[30000];

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) cin >> str[i];

    for (int i = 0; i < str[0].length(); i++) {
        bool b = true;
        char c = str[0][i];
        for (int j = 0; j < n; j++) {
            if (str[j][i] != c) {b = false; break;}
        }
        if (b) ans++;
        else {cout << ans; return 0;}
    }
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector<string> v;
    string t[30];
    string ch,ch1;
    int n,i,l,k,s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>ch;
        v.push_back(ch);
    }
    ch1=v.at(0);
    l=ch1.size();
    t[l]="";

    for(int j=0;j<l;j++){
        t[j]=ch1.substr(0,l-j);
    }
    k=1;
    s=0;
    while(k<n){

     if((v.at(k)).find(t[s])==ch1.find(t[s])){k++;}
     else
         {k=1;
         s++;}
    if(k==n){cout<<t[s].size()<<endl; return 0;}

    }

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    vector<string> v;
    string t[30];
    string ch,ch1;
    int n,i,l,k,s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>ch;
        v.push_back(ch);
    }
    ch1=v.at(0);
    l=ch1.size();
    t[l]="";

    for(int j=0;j<l;j++){
        t[j]=ch1.substr(0,l-j);
    }
    k=1;
    s=0;
    while(k<n){

     if((v.at(k)).find(t[s])!=-1){k++;}
     else
         {k=1;
         s++;}
     if(k==n){cout<<t[s].size()<<endl; return 0;}

    }
    for(int m=0;m<=l;m++){
        cout<<"t["<<m<<"]="<<t[m]<<endl;
    }
}


#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int n;
string a[30001];
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=0;i<a[1].size();i++)
		for(int j=2;j<=n;j++)
			if(a[j][i]!=a[1][i])
			{
				cout<<i;
				return 0;
			}
	cout<<a[1].size();
	return 0;
}


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

int main()
{
    int n,counter1=1,counter2=0;
    cin>>n;
    string arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<arr[0].size();i++){
        counter1=1;
        for(int j=0;j<n-1;j++){
            if(arr[j][i]==arr[j+1][i])
                counter1++;
        }
        if(counter1==n)
            counter2++;

        if((counter2>0 && counter1!=n) || (i==0 && counter2==0)){
            cout<<counter2;
            return 0;
        }
    }
    cout<<counter2;

    return 0;
}


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

int main()
{
    int n,counter1=1,counter2=0;
    cin>>n;
    string arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<arr[0].size();i++){
        counter1=1;
        for(int j=0;j<n-1;j++){
            if(arr[j][i]==arr[j+1][i])
                counter1++;
        }
        if(counter1==n)
            counter2++;

        if(counter2>0 && counter1!=n){
            cout<<counter2;
            return 0;
        }
    }
    cout<<counter2;

    return 0;
}


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

int main()
{
    int n,counter1=1,counter2=0;
    cin>>n;
    string arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    for(int i=0;i<arr[i].size();i++){
        counter1=1;
        for(int j=0;j<n-1;j++){
            if(arr[j][i]==arr[j+1][i])
                counter1++;
        }
        if(counter1==n)
            counter2++;

        if(counter2>0 && counter1!=n){
            cout<<counter2;
            return 0;
        }
    }
    cout<<counter2;

    return 0;
}


#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define ll long long

int main()
{
	vector<string> input;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> input[i];
	int res = 0;
	for (int i = 0; i < 20; ++i)
	{
		int j;
		for (j = 0; j < n - 1; ++j)
		{
			if (input[i][j] != input[i][j + 1])
				break;
		}
		if (j == n - 1)
			res++;
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
vector<string> input;
int n;
int check(int a)
{
	for (int i = 0; i < n - 1; ++i)
		if (input[i][a] != input[i + 1][a])
			return 0;
	return 1;
}
int main()
{
	cin >> n;
	input.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> input[i];
	int res = 0;
	int size = input[0].size();
	for (int i = 0; i < size; ++i)
	{
		if (!check(i))
			break;
		res += check(i);
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
vector < vector<int>> input(3, vector<int>(3));
vector<int> r(3);
vector<int> c(3);

int main()
{
	vector<string> input;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> input[i];
	int res = 0;
	for (int i = 0; i < 20; ++i)
	{
		for (int j = 0; j < n - 1; ++j)
		{
			if (input[i][j] != input[i][j + 1])
				break;
		}
		if (j == n - 1)
			res++;
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
vector < vector<int>> input(3, vector<int>(3));
vector<int> r(3);
vector<int> c(3);

int main()
{
	vector<string> input;
	int n;
	input.resize(n);
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> input[i];
	int res = 0;
	for (int i = 0; i < 20; ++i)
	{
		int j;
		for (j = 0; j < n - 1; ++j)
		{
			if (input[j][i] != input[j+1][i])
				break;
		}
		if (j == n - 1)
			res++;
	}
	cout << res << endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<memory.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
vector < vector<int>> input(3, vector<int>(3));
vector<int> r(3);
vector<int> c(3);

int main()
{
	vector<string> input;
	int n;
	cin >> n;
	input.resize(n);
	for(int i = 0; i < n; ++i)
		cin >> input[i];
	int res = 0;
	for (int i = 0; i < 20; ++i)
	{
		int j;
		for (j = 0; j < n - 1; ++j)
		{
			if (input[j][i] != input[j+1][i])
				break;
		}
		if (j == n - 1)
			res++;
	}
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    long int n;
    cin>>n;
    string s[n];
    char ch;
    long int i,j;
    for(i=0;i<n;++i)
        cin>>s[i];

    for(j=0;j<s[0].length();++j)
      {

          for(i=1;i<n;++i)
            {
                if(s[0][j]==s[i][j])
                  continue;

                else
                  break;
            }

          if(i==n)
             continue;

          else
            break;
      }

      cout<<j;

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define itn int
#define tin int
#define tni int
#define nit int
#define nti int
#define inr int
#define ll long long
#define re return
inline int in()
{
	int s=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0')
	{
		if(c=='-')
		{
			f=-1;
		}
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		s*=10;
		s+=c-'0';
		c=getchar();
	}
	return s*f;
}
int n,gy,zjy;
string s[100416];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	for(zjy=0;zjy<s[1].length();zjy++)
	{
		gy=1;
		for(int i=1;i<n;i++)
		{
			if(s[i][zjy]!=s[i+1][zjy])
			{
				gy=0;
				break;
			}
		}
		if(!gy)
		{
			cout<<zjy;
			re 0;
		}
	}
	re 0;
}
/*
zjy
*/


#include/*\~CeLaMbDa\*/<stdio.h>

char a[1005][1005] = {'\0'};
int main(int argc, char** args) {
	int n = 0, ans = 0;
	scanf("%d", &n);
	for(int i = 0;i < n;i++) {
		scanf("%s", a[i]);
	}
	while(true) {
		char mode = a[0][ans];
		for(int i = 0;i < n;i++) {
			if(a[i][ans] != mode) {
				return printf("%d", ans), 0;
			}
		}
		ans++;
	}
	printf("%d", ans);
}


#include/*\~CeLaMbDa\*/<stdio.h>

char a[10005][10005] = {'\0'};
int main(int argc, char** args) {
	int n = 0, ans = 0;
	scanf("%d", &n);
	for(int i = 0;i < n;i++) {
		scanf("%s", a[i]);
	}
	while(true) {
		char mode = a[0][ans];
		for(int i = 0;i < n;i++) {
			if(a[i][ans] != mode) {
				return printf("%d", ans), 0;
			}
		}
		ans++;
	}
	printf("%d", ans);
}


#include/*\~CeLaMbDa\*/<stdio.h>

char a[30001][100] = {'\0'};
int main(int argc, char** args) {
	int n = 0, ans = 0;
	scanf("%d", &n);
	for(int i = 0;i < n;i++) {
		scanf("%s", a[i]);
	}
	while(true) {
		char mode = a[0][ans];
		for(int i = 0;i < n;i++) {
			if(a[i][ans] != mode) {
				return printf("%d", ans), 0;
			}
		}
		ans++;
	}
	printf("%d", ans);
}


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

int main () {
    cin >> n;
    string prefix; cin >> prefix;
    for (int i = 0; i<n-1) {
        string new_prefix = "";
        string str; cin >> str;
        for (int j = 0; j<min(str.length(),prefix.length()); j++) {
            if (str.at(j) == prefix.at(j)) new_prefix += prefix.at(j);
            else break;
        }
        prefix = new_prefix;
    }
    cout << prefix.length() << endl;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
struct tetris {
	int n;
	int* arr;

};
int maxInt(int* arr) {
	int max = arr[0];
	for (int i = 0; i < 10; ++i) {
		if (arr[i] > max) {
			max = arr[i];
		}
	}
	return max;
}
int main() {
	int t;
	cin >> t;
	tetris* arr = new tetris[t];

	for (int i = 0; i < t; i++) {
		cin >> arr[i].n;
		arr[i].arr = new int[arr[i].n];
		for (int j = 0; j < arr[i].n; j++) {
			cin >> arr[i].arr[j];
		}
	}

	for (int i = 0; i < t; i++) {
		bool b = 0;
		int max = maxInt(arr[i].arr);

		for (int j = 0; j < arr[i].n - 1; ++j) {
			if ((max - arr[i].arr[j]) % 2 != 0) {
				b = 1;
				break;
			}
		}

		if (b == 1) {
			cout << "NO" << endl;
			b = 0;
		}
		else {
			cout << "YES" << endl;
			b = 0;
		}
	}
}


// 154.8.222.126
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#pragma warning (disable:4996)
#define fr(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
typedef long long ll;
inline int in() {
	int f = 1, ans, ch;
	while ((ch = getchar()) < '0' || ch > '9') if ('-' == ch) { ch = getchar(), f = -1; break; }
	ans = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9') ans = (ans << 3) + (ans << 1) + ch - '0';
	return f * ans;
}
/*int a[200010], b[200010];
int c[200010], d[200010];
int main()
{
	int n;
	cin >> n;
	fr(i, 1, n)
		a[i] = in();
	fr(i, 1, n)
		b[i] = in();
	fr(i, 1, n) {
		c[i] = a[i] - b[i];
		d[i] = b[i] - a[i];
	}
		//0 3 -2 5 -1
	//0 -3 2 -5 1
	//  (ai+aj) - (bi+bj) > 0
}*/
int t, n;
int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		int odd = 0, even = 0;
		int x;
		fr(i, 1, n) {
			cin >> x;
			if (x & 1)
				odd = 1;
			else
				even = 1;
		}
		if (odd == 1 && even == 1)
			puts("NO");
		else
			puts("YES");
	}
	return 0;
}

/*int t, n;
int a[110];
struct cmp {
	bool operator () (const int a, const int b)const  {
		if (a == b)
			return 0;
		return a > b;
	}
};
int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		set<int,cmp>s;
		int x;
		fr(i, 1, n)
			cin >> x,s.insert(x);
		if (s.size() == 1) {
			puts("YES");
		}
		else {
			auto it = s.begin();
			x = *it;
			it++;
			int y = *it;
			if ((x - y) & 1)
				puts("NO");
			else
				puts("YES");
		}
	}
		return 0;
}*/

/*const int MAX = 100010;
int minTree[MAX << 2 + 1], maxTree[MAX << 2 + 1];
int n, k;
inline void pushupMax(int p) {
	maxTree[p] = max(maxTree[p << 1], maxTree[p << 1 | 1]);
	return;
}
inline void pushupMin(int p) {
	minTree[p] = min(minTree[p << 1], minTree[p << 1 | 1]);
	return;
}
void build(int s, int t, int p) {
	if (s == t) {
		scanf("%d", &minTree[p]);
		maxTree[p] = minTree[p];
		return;
	}
	int mid = (s + t) >> 1;
	build(s, mid, p << 1);
	build(mid + 1, t, p << 1 | 1);
	pushupMax(p);
	pushupMin(p);
	return;
}
pair<int,int> query(int s,int t,int l,int r,int p) {
	if (l <= s && t <= r)
		return make_pair(minTree[p], maxTree[p]);
	int mid = (s + t) >> 1;
	return make_pair(min(query(s, mid, l, r, p << 1).first, query(mid + 1, t, l, r, p << 1 | 1).first),
		max(query(s, mid, l, r, p << 1).second, query(mid + 1, t, l, r, p << 1 | 1).second));
}
vector<int>minn, maxx;
int main()
{
	scanf("%d%d", &n, &k);
	build(1, n, 1);
	fr(i, 1, n - k + 1)
		minn.push_back(query(i, i + k - 1, 1, n, 1).first), maxx.push_back(query(i, i + k - 1, 1, n, 1).second);
	for (auto i : minn)
		cout << i << " ";
	cout << endl;
	for (auto i : maxx)
		cout << i << " ";
	cout << endl;
	return 0;
}*/


// 154.8.222.126
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#pragma warning (disable:4996)
#define fr(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
typedef long long ll;
int t, n;
int a[110];
int maxx = -0x7fffffff, minn = 0x7fffffff;
struct cmp {
	bool operator () (const int a, const int b)const  {
		if (a == b)
			return 0;
		return a > b;
	}
};
int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		set<int,cmp>s;
		int x;
		fr(i, 1, n)
			cin >> x,s.insert(x);
		if (s.size() == 1) {
			puts("YES");
		}
		else {
			auto it = s.begin();
			x = *it;
			it++;
			int y = *it;
			if ((x - y) & 1)
				puts("NO");
			else
				puts("YES");
		}
	}
		return 0;
}

/*const int MAX = 100010;
int minTree[MAX << 2 + 1], maxTree[MAX << 2 + 1];
int n, k;
inline void pushupMax(int p) {
	maxTree[p] = max(maxTree[p << 1], maxTree[p << 1 | 1]);
	return;
}
inline void pushupMin(int p) {
	minTree[p] = min(minTree[p << 1], minTree[p << 1 | 1]);
	return;
}
void build(int s, int t, int p) {
	if (s == t) {
		scanf("%d", &minTree[p]);
		maxTree[p] = minTree[p];
		return;
	}
	int mid = (s + t) >> 1;
	build(s, mid, p << 1);
	build(mid + 1, t, p << 1 | 1);
	pushupMax(p);
	pushupMin(p);
	return;
}
pair<int,int> query(int s,int t,int l,int r,int p) {
	if (l <= s && t <= r)
		return make_pair(minTree[p], maxTree[p]);
	int mid = (s + t) >> 1;
	return make_pair(min(query(s, mid, l, r, p << 1).first, query(mid + 1, t, l, r, p << 1 | 1).first),
		max(query(s, mid, l, r, p << 1).second, query(mid + 1, t, l, r, p << 1 | 1).second));
}
vector<int>minn, maxx;
int main()
{
	scanf("%d%d", &n, &k);
	build(1, n, 1);
	fr(i, 1, n - k + 1)
		minn.push_back(query(i, i + k - 1, 1, n, 1).first), maxx.push_back(query(i, i + k - 1, 1, n, 1).second);
	for (auto i : minn)
		cout << i << " ";
	cout << endl;
	for (auto i : maxx)
		cout << i << " ";
	cout << endl;
	return 0;
}*/


// 154.8.222.126
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#pragma warning (disable:4996)
#define fr(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
typedef long long ll;
int t, n;
int a[110];
int maxx = -0x7fffffff, minn = 0x7fffffff;
int main()
{
	cin >> t;
	while (t--) {
		cin >> n;
		fr(i, 1, n)
			cin >> a[i], maxx = max(maxx, a[i]), minn = min(minn, a[i]);
		if (n == 1)
			puts("YES");
		else {
			if ((maxx - minn) & 1)
				puts("NO");
			else
				puts("YES");
		}
		maxx = -0x7fffffff, minn = 0x7fffffff;
	}
		return 0;
}

/*const int MAX = 100010;
int minTree[MAX << 2 + 1], maxTree[MAX << 2 + 1];
int n, k;
inline void pushupMax(int p) {
	maxTree[p] = max(maxTree[p << 1], maxTree[p << 1 | 1]);
	return;
}
inline void pushupMin(int p) {
	minTree[p] = min(minTree[p << 1], minTree[p << 1 | 1]);
	return;
}
void build(int s, int t, int p) {
	if (s == t) {
		scanf("%d", &minTree[p]);
		maxTree[p] = minTree[p];
		return;
	}
	int mid = (s + t) >> 1;
	build(s, mid, p << 1);
	build(mid + 1, t, p << 1 | 1);
	pushupMax(p);
	pushupMin(p);
	return;
}
pair<int,int> query(int s,int t,int l,int r,int p) {
	if (l <= s && t <= r)
		return make_pair(minTree[p], maxTree[p]);
	int mid = (s + t) >> 1;
	return make_pair(min(query(s, mid, l, r, p << 1).first, query(mid + 1, t, l, r, p << 1 | 1).first),
		max(query(s, mid, l, r, p << 1).second, query(mid + 1, t, l, r, p << 1 | 1).second));
}
vector<int>minn, maxx;
int main()
{
	scanf("%d%d", &n, &k);
	build(1, n, 1);
	fr(i, 1, n - k + 1)
		minn.push_back(query(i, i + k - 1, 1, n, 1).first), maxx.push_back(query(i, i + k - 1, 1, n, 1).second);
	for (auto i : minn)
		cout << i << " ";
	cout << endl;
	for (auto i : maxx)
		cout << i << " ";
	cout << endl;
	return 0;
}*/


#define _CRT_SECURE_NO_WARNINGS
#define mp make_pair
#define ll long long
#define pb push_back
#define all(x) begin(x), end(x)
const int INF = 1e8;
#pragma comment(linker, "/STACK:10000000000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<sstream>
using namespace std;
vector< int > g[1010000];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vector< int > a(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];
		if (n == 1)
		{
			cout << "YES" << endl;
			continue;
		}
		int counter = 0;
		for (int i = 0; i < n; i++)
		{
			if (a[i] % 2 == 1)
				counter++;
		}
		if (counter == n || counter == 0)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define mp make_pair
#define ll long long
#define pb push_back
#define all(x) begin(x), end(x)
const int INF = 1e8;
#pragma comment(linker, "/STACK:10000000000")
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<sstream>
using namespace std;
vector< int > g[1010000];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		vector< int > a(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];
		if (n == 1)
		{
			cout << "YES" << endl;
			continue;
		}
		sort(all(a));
		bool flag = true;
		for (int i = 1; i < n; i++)
		{
			if (a[i] - a[i - 1] % 2 == 1)
			{
				cout << "NO" << endl;
				flag = false;
				break;
			}
		}
		if (flag)
			cout << "YES" << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

void main() {
	int t(0);
	cin >> t;

	for (size_t i(0); i < t; ++i) {

		int n(0);
		cin >> n;
		int* a = new int[n];
		for (size_t i(0); i < n; ++i)
			cin >> a[i];

		if (n == 1)
			cout << "YES\n";
		else {
			int c = a[0] % 2;
			bool t(1);
			for (int i(1); i < n; ++i)
				if (a[i] % 2 != c) {
					t = 0;
					break;
				}
			cout <<( t ? "YES\n" : "NO\n");
		}
	}
}


#include <iostream>

using namespace std;

void main() {
	int t(0);
	cin >> t;

	for (size_t i(0); i < t; ++i) {
		int n(0);
		cin >> n;
		int* a = new int[n];
		for (size_t i(0); i < n; ++i)
			cin >> a[i];

		if (n == 1)
			cout << "YES\n";
		else {
			int c = a[0] % 2;
			bool t(1);
			for (int i(1); i < n; ++i)
				if (a[i] % 2 != c) {
					t = 0;
					break;
				}
			cout <<( t ? "YES\n" : "NO\n");
		}
	}
}


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

typedef long long ll;

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int> a(n);
        for(int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int cnt = 0;
        for(int i = 0; i < n-1; ++i) {
            if(a[i] < a[n-1]) ++cnt;
        }
        if(cnt >= 3) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
        }
    }

	return 0;
}


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

typedef long long ll;

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int k0 = 0, k1 = 0;
        for(int i = 0; i < n; ++i) {
            int a;
            cin >> a;
            if(a % 2 == 0)  ++k0;
            else ++k1;
        }
        if(k0 == 0 || k1 == 0) cout << "YES" << endl;
        else cout << "NO" << endl;

    }

	return 0;
}


#include <iostream>
using namespace std;

int min_el(int array[], int n);

int main()
{
	int t; // кол-во тестов
	cin >> t;

#pragma region B
	//for (int i = 0; i < t; i++)
	//{
	//	int n; // кол-во чисел в массиве
	//	cin >> n;

	//	int* a = new int[n]; // массив чисел

	//	for (int j = 0; j < n; j++)
	//		cin >> a[j]; // числа массива

	//	delete[] a;
	//}
#pragma endregion

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца
		}

		// T E T R I S

		string answer = "NO";

		for (int c = 0; c < n; c++)
		{
			// прибавили один столбик
			if (a[c] <= n - 1)
				a[c] = a[c] + 2;
			// минимальное заполнение в рядке
			int min = min_el(a, n);
			if (min != 0) // у каждого столбика есть этот минимум, отличный от нуля
			{
				for (int d = 0; d < n; d++)
					a[d] = a[d] - min; // минус строчки в тетрисе
			}

			// проверка на завершение игры (все столбики равны меж собою)
			bool flag = true;
			int e = a[0];
			for (int g = 0; g < n; g++)
				if (a[g] != e) // какой-то столбик пидор
				{
					flag = false;
					break;
				}
			if (flag)
			{
				answer = "YES";
				break;
			}
		}

		cout << answer << endl;

	}

	return 0;
}

int min_el(int array[], int n)
{
	int a = array[0];
	for (int i = 1; i < n; i++)
		if (array[i] < a)
			a = array[i];
	return a;
}


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

int min_el(int array[], int n);

int main()
{
	int t; // кол-во тестов
	cin >> t;

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца
		}

		string answer = "YES";

		for (int j = 1; j < n; j++)
		{
			if (a[j] % 2 != a[0] % 2)
			{
				answer = "NO";
				break;
			}
		}

		cout << answer << endl;

		delete[] a;
	}

	return 0;
}

int min_el(int array[], int n)
{
	int a = array[0];
	for (int i = 1; i < n; i++)
		if (array[i] < a)
			a = array[i];
	return a;
}


#include <iostream>
using namespace std;

int main()
{
	int t; // кол-во тестов
	cin >> t;

#pragma region B
	//for (int i = 0; i < t; i++)
	//{
	//	int n; // кол-во чисел в массиве
	//	cin >> n;

	//	int* a = new int[n]; // массив чисел

	//	for (int j = 0; j < n; j++)
	//		cin >> a[j]; // числа массива

	//	delete[] a;
	//}
#pragma endregion

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца

			while (a[j] > 0 && a[j] < n) // максимально заполняем столбец
			{
				a[j] = a[j] + 2;
			}
		}

		bool answer = true;
		for (int i = 0; i < n; i++)
			if (a[i] != n)
				answer = false;

		if (answer)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;

	}

	return 0;
}


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

int min_el(int array[], int n);

int main()
{
	int t; // кол-во тестов
	cin >> t;

#pragma region B
	//for (int i = 0; i < t; i++)
	//{
	//	int n; // кол-во чисел в массиве
	//	cin >> n;

	//	int* a = new int[n]; // массив чисел

	//	for (int j = 0; j < n; j++)
	//		cin >> a[j]; // числа массива

	//	delete[] a;
	//}
#pragma endregion

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца
		}

		// T E T R I S

		string answer = "NO";

		for (int c = 0; c < n; c++)
		{
			// прибавили один столбик
			if (a[c] <= n - 1)
				a[c] = a[c] + 2;
			// минимальное заполнение в рядке
			int min = min_el(a, n);
			if (min != 0) // у каждого столбика есть этот минимум, отличный от нуля
			{
				for (int d = 0; d < n; d++)
					a[d] = a[d] - min; // минус строчки в тетрисе
			}

			// проверка на завершение игры (все столбики равны меж собою)
			bool flag = true;
			int e = a[0];
			for (int g = 0; g < n; g++)
				if (a[g] != e) // какой-то столбик пидор
				{
					flag = false;
					break;
				}
			if (flag)
			{
				answer = "YES";
				break;
			}
		}
		cout << answer << endl;

	}

	return 0;
}

int min_el(int array[], int n)
{
	int a = array[0];
	for (int i = 1; i < n; i++)
		if (array[i] < a)
			a = array[i];
	return a;
}


#include <iostream>
using namespace std;

int min_el(int array[], int n);

int main()
{
	int t; // кол-во тестов
	cin >> t;

#pragma region B
	//for (int i = 0; i < t; i++)
	//{
	//	int n; // кол-во чисел в массиве
	//	cin >> n;

	//	int* a = new int[n]; // массив чисел

	//	for (int j = 0; j < n; j++)
	//		cin >> a[j]; // числа массива

	//	delete[] a;
	//}
#pragma endregion

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца
		}

		// T E T R I S

		string answer = "NO";

		for (int c = 0; c < n; c++)
		{
			// прибавили один столбик
			if (a[c] <= n - 1)
				a[c] = a[c] + 2;
			// минимальное заполнение в рядке
			int min = min_el(a, n);
			if (min != 0) // у каждого столбика есть этот минимум, отличный от нуля
			{
				for (int d = 0; d < n; d++)
					a[d] = a[d] - min; // минус строчки в тетрисе
			}

			// проверка на завершение игры (все столбики равны меж собою)
			bool flag = true;
			int e = a[0];
			for (int g = 0; g < n; g++)
				if (a[g] != e) // какой-то столбик пидор
				{
					flag = false;
					break;
				}
			if (flag)
			{
				answer = "YES";
				break;
			}
		}
		cout << answer << endl;

	}

	return 0;
}

int min_el(int array[], int n)
{
	int a = array[0];
	for (int i = 1; i < n; i++)
		if (array[i] < a)
			a = array[i];
	return a;
}


#include <iostream>
using namespace std;

int main()
{
	int t; // кол-во тестов
	cin >> t;

#pragma region B
	//for (int i = 0; i < t; i++)
	//{
	//	int n; // кол-во чисел в массиве
	//	cin >> n;

	//	int* a = new int[n]; // массив чисел

	//	for (int j = 0; j < n; j++)
	//		cin >> a[j]; // числа массива

	//	delete[] a;
	//}
#pragma endregion

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца

			while (a[j] > 0 && a[j] < n) // максимально заполняем столбец
			{
				a[j] = a[j] + 2;
			}
		}

		bool answer = true;
		for (int i = 1; i < n; i++)
			if (a[i] != a[i - 1])
				answer = false;

		if (answer)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;

	}

	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int t; // кол-во тестов
	cin >> t;

#pragma region B
	//for (int i = 0; i < t; i++)
	//{
	//	int n; // кол-во чисел в массиве
	//	cin >> n;

	//	int* a = new int[n]; // массив чисел

	//	for (int j = 0; j < n; j++)
	//		cin >> a[j]; // числа массива

	//	delete[] a;
	//}
#pragma endregion

	for (int i = 0; i < t; i++)
	{
		int n; // количество столбцов на поле тетриса
		cin >> n;

		int* a = new int[n]; // высота каждого столбца

		for (int j = 0; j < n; j++)
		{
			cin >> a[j]; // вводим высоту столбца

			while (a[j] > 0 && a[j] < n) // максимально заполняем столбец
			{
				a[j] = a[j] + 2;
			}
		}

		bool answer = true;
		for (int i = 1; i < n; i++)
			if (a[i] != a[i - 1])
				answer = false;

		if (answer)
			cout << "YES";
		else
			cout << "NO";

	}

	return 0;
}