#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::vector;

int main () {

 int n;
 cin >> n;

 const long long mod = (long long)1e9 + 7LL;
 const int maxn = 500;

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

 long long rooted[maxn][maxn];
 long long non_rooted[maxn][maxn];

 for (int i = 0; i < n; ++i) {
  rooted[i][i] = non_rooted[i][i] = 1;
 }
 for (int i = 0; i + 1 < n; ++i) {
  rooted[i][i+1] = 1;
  non_rooted[i][i+1] = (p[i] < p[i+1] ? 2 : 1);
 }

 for (int sz = 3; sz <= n; ++sz) {
  for (int left = 0; left + sz <= n; ++left) {
   int right = left + sz - 1;
   //rooted
   rooted[left][right] = rooted[left + 1][right];
   for (int mid = left + 2; mid <= right; ++mid) {
    if (p[left + 1] > p[mid]) {
     continue;
    }
    rooted[left][right] += (rooted[left+1][mid-1] * non_rooted[mid][right]) % mod;
    rooted[left][right] %= mod;
   }
   //non-rooted
   non_rooted[left][right] = rooted[left][right];
   for (int mid = left + 1; mid <= right; ++mid) {
    if (p[left] > p[mid]) {
     continue;
    }
    non_rooted[left][right] += (rooted[left][mid-1] * non_rooted[mid][right]) % mod;
    non_rooted[left][right] %= mod;
   }
  }
 }

 cout << rooted[0][n-1]; //% mod ?
 return 0;
}


#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::vector;

int main () {

 int n;
 cin >> n;

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

 const long long mod = (long long)1e9 + 7LL;
 vector<vector<long long> > rooted(n, vector<long long>(n)); // 0 ?
 vector<vector<long long> > non_rooted(n, vector<long long>(n)); // 0 ?

 for (int i = 0; i < n; ++i) {
  rooted[i][i] = non_rooted[i][i] = 1;
 }
 for (int i = 0; i + 1 < n; ++i) {
  rooted[i][i+1] = 1;
  non_rooted[i][i+1] = (p[i] < p[i+1] ? 2 : 1);
 }

 for (int sz = 3; sz <= n; ++sz) {
  for (int left = 0; left + sz <= n; ++left) {
   int right = left + sz - 1;
   //rooted
   rooted[left][right] = rooted[left + 1][right];
   for (int mid = left + 2; mid <= right; ++mid) {
    if (p[left + 1] > p[mid]) {
     continue;
    }
    rooted[left][right] += (rooted[left+1][mid-1] * non_rooted[mid][right]) % mod;
    rooted[left][right] %= mod;
   }
   //non-rooted
   non_rooted[left][right] = rooted[left][right];
   for (int mid = left + 1; mid <= right; ++mid) {
    if (p[left] > p[mid]) {
     continue;
    }
    non_rooted[left][right] += (rooted[left][mid-1] * non_rooted[mid][right]) % mod;
    non_rooted[left][right] %= mod;
   }
  }
 }

 cout << rooted[0][n-1]; //% mod ?
 return 0;
}


#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::vector;

int main () {

 int n;
 cin >> n;

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

 const long long mod = (long long)1e9 + 7LL;
 vector<vector<long long> > rooted(n, vector<long long>(n)); // 0 ?
 vector<vector<long long> > non_rooted(n, vector<long long>(n)); // 0 ?

 for (int i = 0; i < n; ++i) {
  rooted[i][i] = non_rooted[i][i] = 1;
 }
 for (int i = 0; i + 1 < n; ++i) {
  rooted[i][i+1] = 1;
  non_rooted[i][i+1] = (p[i] < p[i+1] ? 2 : 1);
 }

 for (int sz = 3; sz <= n; ++sz) {
  for (int left = 0; left + sz <= n; ++left) {
   int right = left + sz - 1;
   //rooted
   rooted[left][right] = rooted[left + 1][right];
   for (int mid = left + 2; mid <= right; ++mid) {
    if (p[left + 1] > p[mid]) {
     continue;
    }
    rooted[left][right] += (rooted[left+1][mid-1] * non_rooted[mid][right]) % mod;
   }
   rooted[left][right] %= mod;
   //non-rooted
   non_rooted[left][right] = rooted[left][right];
   for (int mid = left + 1; mid <= right; ++mid) {
    if (p[left] > p[mid]) {
     continue;
    }
    non_rooted[left][right] += (rooted[left][mid-1] * non_rooted[mid][right]) % mod;
   }
   non_rooted[left][right] %= mod;
  }
 }

 cout << rooted[0][n-1]; //% mod ?
 return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#define ull unsigned long long
#define Maxn 1000010
#define mod 1000000009
using namespace std;
#define maxn 505
int dp[maxn][maxn];
int num[maxn];
int f(int l,int r){
    if(l>r) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    dp[l][r]=0;
    for(int i=l;i<=r;i++)
        if(i==r||num[l]<num[i+1]) dp[l][r]=(dp[l][r]+f(l+1,i)+f(i+1,r))%mod;
    return dp[l][r];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&num[i]),dp[i][i]=1;
    printf("%d\n",f(1,n-1));
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#define ll unsigned long long
#define Maxn 1000010
#define mod 1000000007
using namespace std;
#define maxn 505
ll dp[maxn][maxn];
int num[maxn];
ll f(int l,int r){
    if(l>r) return 1;
    if(dp[l][r]!=-1) return dp[l][r];
    dp[l][r]=0;
    for(int i=l;i<=r;i++)
        if(i==r||num[l]<num[i+1]) dp[l][r]=(dp[l][r]+f(l+1,i)*f(i+1,r))%mod;
    return dp[l][r];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&num[i]),dp[i][i]=1;
    printf("%I64d\n",f(1,n-1));
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#define ull unsigned long long
#define Maxn 1000010
#define mod 1000000009
using namespace std;
#define maxn 505
int dp[maxn][maxn];
int num[maxn];
int f(int l,int r){
    if(l>r) return 0;
    if(dp[l][r]!=-1) return dp[l][r];
    dp[l][r]=0;
    for(int i=l;i<=r;i++)
        if(i==r||num[l]<num[i+1]) dp[l][r]=(dp[l][r]+f(l+1,i)+f(i+1,r))%mod;
    return dp[l][r];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    int n;
    scanf("%d",&n);
    if(n==1){ puts("1"); return 0;}
    for(int i=0;i<n;i++) scanf("%d",&num[i]),dp[i][i]=1;
    printf("%d\n",f(1,n-1));
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#define ll unsigned long long
#define Maxn 1000010
#define mod 1000000009
using namespace std;
#define maxn 505
ll dp[maxn][maxn];
int num[maxn];
ll f(int l,int r){
    if(l>r) return 1;
    if(dp[l][r]!=-1) return dp[l][r];
    dp[l][r]=0;
    for(int i=l;i<=r;i++)
        if(i==r||num[l]<num[i+1]) dp[l][r]=(dp[l][r]+f(l+1,i)*f(i+1,r))%mod;
    return dp[l][r];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",&num[i]),dp[i][i]=1;
    printf("%I64d\n",f(1,n-1));
    return 0;
}


#pragma comment(linker,"/STACK:102400000,102400000")
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <algorithm>
#include <bitset>
#include <functional>
#include <numeric>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <stack>
#include <iterator>
#include <memory>
#include <utility>
#include <string>
#include <sstream>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define mset(a) memset(a,0,sizeof(a))
#define mmset(a) memset(a,-1,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))

typedef double lf;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<lf,lf> pdd;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<pii> vpii;

const int inf=1000000007;
const ll linf=1000000000000000000LL;
const ull ulinf=(1ULL<<63)-10ULL;
const lf eps=0.000001;
const lf pi=3.14159265358979323846;

template <class T> T abs(T a){return a>=0?a:-a;}
template <class T> int sign(T a){return a>eps?1:a<-eps?-1:0;}
template <class T> T sqr(T a){return a*a;}
template <class T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
template <class T> T mod(T a,T b){T ret=a%b;if(ret<0)ret+=b;return ret;}
template <class T> T lowbit(T x){return x&-x;}
ll addmod(ll a,ll b,ll c){return ((a+b)%c+c)%c;}
ll mulmod(ll a,ll b,ll c){if(b==0LL)return 0LL;ll ret=mulmod(a,b>>1,c);ret=(ret+ret)%c;if(b&1LL)ret=(ret+a)%c;return ret;}
ll powmod(ll a,ll b,ll c){if(b==0LL)return 1LL;ll ret=powmod(a,b>>1,c);ret=ret*ret%c;if(b&1LL)ret=ret*a%c;return ret;}
ll modinv(ll a,ll b){return powmod(a,b-2LL,b);}
template <class T> void maxe(T &a,T b){if(a<b)a=b;}
template <class T> void mine(T &a,T b){if(a>b)a=b;}
int iszero(lf a){return a<=eps&&a>=-eps;}

template <class T> void geti(T &a){a=0;int b=0;char c;while((c=getchar())==' '||c=='\n');if(c=='-')b=1;else a=c-48;while((c=getchar())!=' '&&c!='\n')a=a*10+c-48;if(b)a=-a;}

void fileio_in_out(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
void fileio_txt(){freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);}

//==================================================

#define DEBUG(X)

const int N=505;
const int M=111;
const int K=20;
const ll md=inf;

int test;
int n,m,k;
ll ans;
int a[N];
ll dp[N][N];

ll dfs(int l,int r)
{
    if(dp[l][r]!=-1)
        return dp[l][r];
    if(l>r)
        return 1;
    ll ret=dfs(l+1,r);
    for(int i=l;i<r;i++)
        if(a[i+1]>a[l])
            ret=(ret+dfs(l+1,i)*dfs(i+1,r))%md;
    //printf("%d %d %I64d\n",l,r,ret);
    return dp[l][r]=ret;
}

int main()
{
    //fileio_in_out();
    //fileio_txt();
    //ios::sync_with_stdio(false);cout<<setprecision(15);

    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    mmset(dp);
    ans=dfs(2,n);
    printf("%I64d\n",ans);

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


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[501][501];
int mod = 1e9 + 7;
int se[500];
int was[500][500];
int fun(int l, int r)
{
    if (l >= r)
        return 1;
    if (was[l][r])
        return d[l][r];
    was[l][r] = 1;
    d[l][r] = fun(l + 1, r);

    for(int i = l + 1; i < r; ++i)
    {
        if (se[i + 1] < se[l])
            continue;;
        d[l][r] += (fun(l, i) *(int64) fun(i, r)) % mod;
        d[l][r] %= mod;
    }
    return d[l][r];
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    cout << fun(0, n - 1);
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[2][501][501];
int mod = 1e9 + 7;
int se[500];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    int q = 0;
    if (n == 1)
    {
        cout << 1;
        return 0;
    }
    d[0][0][0] = 1;
    for(int i = 1; i < n; ++i)
    {
        for(int j = n - 1; j >= 0; --j)
            for(int k = se[i] - 1; k >= 0; --k)
            {
                d[q ^ 1][j][se[i]] = 0;
                d[q ^ 1][j + 1][0] = 0;
            }
        for(int j = n - 1; j >= 0; --j)
            for(int k = se[i] - 1; k >= 0; --k)
            {
                if (!d[q][j][k])
                    continue;
                d[q ^ 1][j][se[i]] += d[q][j][k];
                d[q ^ 1][j][se[i]] %= mod;
                d[q ^ 1][j + 1][0] += d[q][j][k];
                d[q ^ 1][j + 1][0] %= mod;
            }
        q ^= 1;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 1; j <= n; ++j)
            ans = (ans + d[q][i][j]) % mod;
    cout << ans;
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[2][501][501];
int mod = 1e9 + 7;
int se[500];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    int q = 0;
    d[0][0][0] = 1;
    for(int i = 1; i < n; ++i)
    {
        for(int j = n - 1; j >= 0; --j)
            for(int k = se[i] - 1; k >= 0; --k)
            {
                d[q ^ 1][j][se[i]] = 0;
                d[q ^ 1][j + 1][0] = 0;
            }
        for(int j = n - 1; j >= 0; --j)
            for(int k = se[i] - 1; k >= 0; --k)
            {
                if (!d[q][j][k])
                    continue
                d[q ^ 1][j][se[i]] += d[q][j][k];
                d[q ^ 1][j][se[i]] %= mod;
                d[q ^ 1][j + 1][0] += d[q][j][k];
                d[q ^ 1][j + 1][0] %= mod;
            }
        q ^= 1;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 1; j <= n; ++j)
            ans = (ans + d[q][i][j]) % mod;
    cout << ans;
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[501][501];
int mod = 1e9 + 7;
int se[500];
int was[500][500];
int fun(int l, int r)
{
    if (l >= r)
        return 1;
    if (was[l][r])
        return d[l][r];
    was[l][r] = 1;
    d[l][r] = fun(l + 1, r);

    for(int i = l + 1; i < r; ++i)
    {
        if (se[i + 1] < se[l])
            continue;;
        d[l][r] += (fun(l, i) *(int64) fun(i, r)) % mod;
        d[l][r] %= mod;
    }
    return d[l][r];
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    cout << fun(1, n - 1);
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[2][501][501];
int mod = 1e9 + 7;
int se[500];
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    int q = 0;
    d[0][0][0] = 1;
    for(int i = 1; i < n; ++i)
    {
        for(int j = n - 1; j >= 0; --j)
            for(int k = se[i] - 1; k >= 0; --k)
            {
                d[q ^ 1][j][se[i]] = 0;
                d[q ^ 1][j + 1][0] = 0;
            }
        for(int j = n - 1; j >= 0; --j)
            for(int k = se[i] - 1; k >= 0; --k)
            {
                if (!d[q][j][k])
                    continue;
                d[q ^ 1][j][se[i]] += d[q][j][k];
                d[q ^ 1][j][se[i]] %= mod;
                d[q ^ 1][j + 1][0] += d[q][j][k];
                d[q ^ 1][j + 1][0] %= mod;
            }
        q ^= 1;
    }
    int ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 1; j <= n; ++j)
            ans = (ans + d[q][i][j]) % mod;
    cout << ans;
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[501][501];
int mod = 1e9 + 7;
int se[500];
int was[500][500];
int fun(int l, int r)
{
    if (l >= r)
        return 1;
    if (was[l][r])
        return d[l][r];
    was[l][r] = 1;
    d[l][r] = fun(l + 1, r);
    for(int i = l + 1; i <= r; ++i)
    {
        if (se[i] < se[l])
            continue;
        d[l][r] += (fun(l + 1, i - 1) *(int64) fun(i, r)) % mod;
        d[l][r] %= mod;
    }
    return d[l][r];
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    cout << fun(1, n - 1);
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>
using namespace std;
#pragma comment(linker, "/STACK:256000000")
#define mp make_pair
#define pb push_back
#define all(C) (C).begin(), (C).end()
#define sz(C) (int)(C).size()
#define PRIME 1103
#define PRIME1 31415
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
//------------------------------------------------------------
int n, m;
int d[501][501];
int mod = 1e9 + 7;
int se[500];
int was[500][500];
int fun(int l, int r)
{
    if (l >= r)
        return 1;
    if (was[l][r])
        return d[l][r];
    was[l][r] = 1;
    for(int i = l + 1; i <= r; ++i)
    {
        if (i != r && se[i + 1] < se[l + 1])
            continue;
        d[l][r] += (fun(l + 1, i) *(int64) fun(i + 1, r)) % mod;
        d[l][r] %= mod;
    }
    return d[l][r];
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n;
    int k = 0;
    for(int i = 0; i < n; ++i)
        cin >> se[i];
    cout << fun(0, n - 1);
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define lowbit(x) x&(-x)
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f
//#include<bits/stdc++.h>
const double pi=4.0*atan(1.0);
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
struct node
{
    int st;
    int en;
    int num;
};
node x[maxn];
int cmp(node xx,node yy)
{
    if(xx.st==yy.st)
        return xx.en<yy.en;
    return xx.st<yy.st;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int i,j;
        for(i=1;i<=n;i++)
            scanf("%d%d",&x[i].st,&x[i].en);
        sort(x+1,x+1+n,cmp);
        int cnt=1;
        x[1].num=1;
        for(i=2;i<=n;i++)
        {
            if(x[i-1].en>=x[i].st)
                x[i].num=x[i-1].num;
            else
            {
                x[i].num=2;
                cnt++;
            }
        }
        if(cnt==1)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=n)
                {
                    if(x[i].num==1)
                        printf("1 ");
                    else
                        printf("2 ");
                }
                else
                {
                    /*if(x[i].num==1)
                        printf("1\n");
                    else
                        printf("2\n");*/
                    puts("2");
                }
            }
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define lowbit(x) x&(-x)
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f
//#include<bits/stdc++.h>
const double pi=4.0*atan(1.0);
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
struct node
{
    int st;
    int en;
    int num;
};
node x[maxn];
int cmp(node xx,node yy)
{
    if(xx.st==yy.st)
        return xx.en<yy.en;
    return xx.st<yy.st;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int i,j;
        for(i=1;i<=n;i++)
            scanf("%d%d",&x[i].st,&x[i].en);
        sort(x+1,x+1+n,cmp);
        int cnt=1;
        x[1].num=1;
        for(i=2;i<=n;i++)
        {
            if(x[i-1].en>=x[i].st)
                x[i].num=x[i-1].num;
            else
                x[i].num=++cnt;
        }
        if(cnt==1)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=n)
                {
                    if(x[i].num==1)
                        printf("1 ");
                    else
                        printf("2 ");
                }
                else
                {
                    if(x[i].num==1)
                        printf("1\n");
                    else
                        printf("2\n");
                }
            }
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define lowbit(x) x&(-x)
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f
//#include<bits/stdc++.h>
const double pi=4.0*atan(1.0);
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
struct node
{
    int st;
    int en;
    int num;
};
node x[maxn];
int cmp(node xx,node yy)
{
    if(xx.st==yy.st)
        return xx.en<yy.en;
    return xx.st<yy.st;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int i,j;
        for(i=1;i<=n;i++)
            scanf("%d%d",&x[i].st,&x[i].en);
        sort(x+1,x+1+n,cmp);
        int cnt=1;
        x[1].num=1;
        int r=x[1].en;
        for(i=2;i<=n;i++)
        {
            if(r>=x[i].st)
            {
                x[i].num=x[i-1].num;
                r=max(r,x[i].en);
            }
            else
            {
                x[i].num=++cnt;
                //r=max(r,x[i].en);
            }
        }
        if(cnt==1)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=n)
                {
                    if(x[i].num==1)
                        printf("1 ");
                    else
                        printf("2 ");
                }
                else
                {
                    /*if(x[i].num==1)
                        printf("1\n");
                    else
                        printf("2\n");*/
                    puts("2");
                }
            }
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define lowbit(x) x&(-x)
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f
//#include<bits/stdc++.h>
const double pi=4.0*atan(1.0);
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
struct node
{
    int st;
    int en;
    int num;
};
node x[maxn];
int cmp(node xx,node yy)
{
    if(xx.st==yy.st)
        return xx.en<yy.en;
    return xx.st<yy.st;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int i,j;
        for(i=1;i<=n;i++)
            scanf("%d%d",&x[i].st,&x[i].en);
        sort(x+1,x+1+n,cmp);
        int cnt=1;
        x[1].num=1;
        for(i=2;i<=n;i++)
        {
            if(x[i-1].en>=x[i].st)
                x[i].num=x[i-1].num;
            else
                x[i].num=++cnt;
        }
        int flag=0;
        for(i=1;i<=n;i++)
        {
            if(x[i].num!=1)
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=n)
                {
                    if(x[i].num%2==1)
                        printf("1 ");
                    else
                        printf("2 ");
                }
                else
                {
                    if(x[i].num%2==1)
                        printf("1\n");
                    else
                        printf("2\n");
                }
            }
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define lowbit(x) x&(-x)
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f
//#include<bits/stdc++.h>
const double pi=4.0*atan(1.0);
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
struct node
{
    int st;
    int en;
    int num;
};
node x[maxn];
int ans[maxn];
int cmp(node xx,node yy)
{
    if(xx.st==yy.st)
        return xx.en<yy.en;
    return xx.st<yy.st;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        memset(ans,0,sizeof(ans));
        int i,j;
        for(i=1;i<=n;i++)
        {
            scanf("%d%d",&x[i].st,&x[i].en);
            x[i].num=i;
        }
        sort(x+1,x+1+n,cmp);
        int cnt=1;
        ans[x[1].num]=1;
        int r=x[1].en;
        /*int flag=0;
        for(i=2;i<=n;i++)
        {
            if(x[i].st<=r)
            {
                r=max(r,s[i].en);
                ans[x[i].num]=1;
            }
            else
            {
                flag=1;
                ans[x[i].num]=2;
            }
        }
        if(!flag)
            puts("-1");
        else
        {
            for(i=1;i<=n;i++)
            {
                printf("%d",ans[i]);
            }
        }*/
        for(i=2;i<=n;i++)
        {
            if(r>=x[i].st)
            {
                ans[x[i].num]=ans[x[i-1].num];
                r=max(r,x[i].en);
            }
            else
            {
                ans[x[i].num]=++cnt;
            }
        }
        if(cnt==1)
            printf("-1\n");
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=n)
                {
                    if(ans[i]==1)
                        printf("1 ");
                    else
                        printf("2 ");
                }
                else
                {
                    if(ans[i]==1)
                        printf("1\n");
                    else
                        printf("2\n");
                }
            }
        }
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<iomanip>
#define lowbit(x) x&(-x)
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f
//#include<bits/stdc++.h>
const double pi=4.0*atan(1.0);
typedef long long ll;
using namespace std;
const int maxn=1e5+10;
struct node
{
    int st;
    int en;
    int num;
};
node x[maxn];
int cmp(node xx,node yy)
{
    if(xx.st==yy.st)
        return xx.en<yy.en;
    return xx.st<yy.st;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int i,j;
        for(i=1;i<=n;i++)
            scanf("%d%d",&x[i].st,&x[i].en);
        sort(x+1,x+1+n,cmp);
        int cnt=1;
        x[1].num=1;
        for(i=2;i<=n;i++)
        {
            if(x[i-1].en>=x[i].st)
                x[i].num=x[i-1].num;
            else
                x[i].num=++cnt;
        }
        if(cnt==1)
        {
            printf("-1\n");
            continue;
        }
        else
        {
            for(i=1;i<=n;i++)
            {
                if(i!=n)
                {
                    if(x[i].num%2==1)
                        printf("1 ");
                    else
                        printf("2 ");
                }
                else
                {
                    if(x[i].num%2==1)
                        printf("1\n");
                    else
                        printf("2\n");
                }
            }
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
		int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n, 1);
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][0] >> v[i][1];
			v[i][2] = i;
		}
		sort(all(v));
		bool ans = 0;
		int last = v[0][1];
		int fill = 1;
		res[v[0][2]] = 1;
		rep (i, 1, n) {
			if (v[i][0] > last) {
				if (fill == 1)fill = 2;
				else fill = 1;
				res[v[i][2]] = fill;
			}else  {
				res[v[i][2]] = fill;
			}
			last = max(last, v[i][1]);
		}
		int maxm = *max_element(all(res));
		if (maxm == 2) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n);
		bool ans = 1;
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][1] >> v[i][0];
			v[i][2] = i;
		}
		sort(all(v));
		int one = 0;
		int two = 0;
		rep (i, 0, n) {
			int x = v[i][1];
			int y = v[i][0];
			int in = v[i][2];
			if (x > one) {
				res[in] = 1;
				one = y;
			}else {
				if (x > two) {
					res[in] = 2;
					two = y;
				}else {
					ans = 0;
				}
			}
		}
		if (ans) {
			if (two == 0) {
				res[n - 1] = 2;
			}
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n, 1);
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][0] >> v[i][1];
			v[i][2] = i;
		}
		sort(all(v));
		bool ans = 0;
		rep (i, 0, n) {
			if (i == 0) {
				if (v[i + 1][0] > v[i][1]) {
					res[v[i][2]] = 2;
					ans = 1;
					break;
				}
			}else if (i == n - 1) {
				if (v[i - 1][1] < v[i][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}
			}else {
				if (v[i][0] > v[i - 1][1] && v[i][1] < v[i + 1][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}
			}
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n, 1);
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][1] >> v[i][0];
			v[i][2] = i;
		}
		sort(all(v));
		bool ans = 0;
		int last = 1e9 + 7;
		for (int i = n - 1; i >= 0; --i) {
			if (i == n - 1) {
				if (v[i][1] > v[i - 1][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}
			}else if (i == 0) {
				if (v[i][0] < last) {
					res[v[i][2]] = 2;
					ans = 1;
					break;
				}
			}else {
				if (v[i][0] < last && v[i][1] > v[i - 1][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}

			}
			last = min(last, v[i][1]);
			//watch(last);
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n, 1);
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][0] >> v[i][1];
			v[i][2] = i;
		}
		sort(all(v));
		bool ans = 0;
		rep (i, 0, n) {
			if (i == 0) {
				if (v[i + 1][0] > v[i][1]) {
					res[v[i][2]] = 2;
					ans = 1;
					break;
				}
			}else if (i == n - 1) {
				if (v[i - 1][1] > v[i][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}
			}else {
				if (v[i][0] > v[i - 1][1] && v[i][1] < v[i + 1][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}
			}
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n, 1);
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][0] >> v[i][1];
			v[i][2] = i;
		}
		sort(all(v));
		bool ans = 0;
		int last = 0;
		rep (i, 0, n) {
			if (i == 0) {
				if (v[i + 1][0] > v[i][1]) {
					res[v[i][2]] = 2;
					ans = 1;
					//break;
				}
			}else if (i == n - 1) {
				if (last < v[i][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					//break;
				}
			}else {
				if (v[i][0] > last && v[i][1] < v[i + 1][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					//break;
				}
				if (v[i][0] == v[i - 1][0] && v[i][1] == v[i - 1][1]) {
					res[v[i][2]] = 2;
					res[v[i - 1][2]] = 2;
					ans = 1;
				}
			}
			last = max(last, v[i][1]);
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n);
		bool ans = 1;
		vector<PII> v(n);
		rep(i, 0, n) {
			cin >> v[i].se >> v[i].fi;
		}
		sort(all(v));
		res[0] = 1;
		res[1] = 2;
		int one = v[0].fi;
		int two = v[1].fi;
		rep (i, 2, n) {
			int x = v[i].se;
			int y = v[i].fi;
			if (x >= one) {
				res[i] = 1;
				one = y;
			}else {
				if (x >= two) {
					res[i] = 2;
					two = y;
				}else {
					ans = 0;
				}
			}
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n);
		bool ans = 1;
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][0] >> v[i][1];
			v[i][2] = i;
		}
		sort(all(v));
		int one = 0;
		int two = 0;
		rep (i, 0, n) {
			int x = v[i][0];
			int y = v[i][1];
			int in = v[i][2];
			if (x > one) {
				res[in] = 1;
				one = y;
			}else {
				if (x > two) {
					res[in] = 2;
					two = y;
				}else {
					ans = 0;
				}
			}
		}
		if (ans) {
			if (two == 0) {
				res[n - 1] = 2;
			}
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n, 1);
		vector<vec<int>> v(n, vec<int> (3));
		rep(i, 0, n) {
			cin >> v[i][0] >> v[i][1];
			v[i][2] = i;
		}
		sort(all(v));
		bool ans = 0;
		int last = 0;
		rep (i, 0, n) {
			if (i == 0) {
				if (v[i + 1][0] > v[i][1]) {
					res[v[i][2]] = 2;
					ans = 1;
					break;
				}
			}else if (i == n - 1) {
				if (last < v[i][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}
			}else {
				if (v[i][0] > last && v[i][1] < v[i + 1][0]) {
					ans = 1;
					res[v[i][2]] = 2;
					break;
				}

			}
			last = max(last, v[i][1]);
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n);
		bool ans = 1;
		vector<PII> v(n);
		rep(i, 0, n) {
			cin >> v[i].se >> v[i].fi;
		}
		sort(all(v));
		res[0] = 1;
		res[1] = 2;
		int one = v[0].fi;
		int two = v[1].fi;
		rep (i, 2, n) {
			int x = v[i].se;
			int y = v[i].fi;
			if (x > one) {
				res[i] = 1;
				one = y;
			}else {
				if (x > two) {
					res[i] = 2;
					two = y;
				}else {
					ans = 0;
				}
			}
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
//#include <numeric> //iota
//#include <sstream>
//#include <cstring>
//#include <tuple>
//#include <random>
//#include <string>
//#include <unordered_set>
//#include <bitset>
//#include <unordered_map>
//#include <stack>
//#include <cmath>
//#include <deque>
//#include <queue>
//#include <list>
#include <array>
using namespace std;
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define vec vector
#define pb push_back
#define pp pop_back
#define fi first
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define se second
#define un_map unordered_map
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define inc_rep(i,a,n,inc) for (int i = a; i < n; i += inc)
#define couts(x) cout << x << "\n"
#define watch(x) cout << #x << " : " << x << endl;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long, long long>  PLII;
template<typename T>
void print(vector<T>& v) {rep(i, 0, (int)v.size()) cout << v[i] << " ";cout << endl;}
int nxt() {int x;cin >> x;return x;}
ll nxtl() {ll x;cin >> x;return x;}
string nxts() {string x;cin >> x;return x;}
double nxtd() {double x; cin >> x; return x;}

int main() {
	IOS;
	int t = nxt();
	while (t--) {
		int n;
		cin >> n;
		vector<int> res(n);
		bool ans = 1;
		vector<PII> v(n);
		rep(i, 0, n) {
			cin >> v[i].fi >> v[i].se;
		}
		sort(all(v));
		res[0] = 1;
		res[1] = 2;
		int one = v[0].se;
		int two = v[1].se;
		rep (i, 2, n) {
			int x = v[i].fi;
			int y = v[i].se;
			if (x > one) {
				res[i] = 1;
				one = y;
			}else {
				if (x > two) {
					res[i] = 2;
					two = y;
				}else {
					ans = 0;
				}
			}
		}
		if (ans) {
			print(res);
		}else {
			couts(-1);
		}
	}
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key1=get<2>(v[0]);int key=get<2>(v[0]);int idx=get<0>(v[0]);vector<int>vv;int idx1=get<0>(v[0]);int cnt=0;
lop(1,n)
{
    if(get<2>(v[i])>key1){key1=get<2>(v[i]);idx1=get<0>(v[i]);}
    if(get<1>(v[i])<=key)
    {
        vv.pb(get<0>(v[i]));
        cnt++;
        if(cnt==1)vv.pb(idx);
    }
    else
    {
      key=key1;idx=idx1;
      if(i==n-1)
      {
          if(idx!=n-1 && key>=get<1>(v[n-1]))vv.pb(n-1);
      }
      cnt=0;
    }
    //cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(vv.size()==n){cout<<-1<<endl;return;}
if(vv.size()==0){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
    if(l<vv.size()){
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
    }
  else cout<<2<<" ";
}
cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key1=get<2>(v[0]);int key=get<2>(v[0]);int idx=get<0>(v[0]);vector<int>vv;int idx1=get<0>(v[0]);int cnt=0;
lop(1,n)
{
    if(get<2>(v[i])>key1){key1=get<2>(v[i]);idx1=get<0>(v[i]);}
    if(get<1>(v[i])<=key)
    {
        cnt++;
    }
    else
    {
        if(cnt==0)vv.pb(idx);
      key=key1;idx=idx1;
      if(i!=n-1)
      cnt=0;
    }
    //cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(cnt==0)vv.pb(idx);
if(vv.size()==0){cout<<-1<<endl;return;}
if(vv.size()==n){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
}
cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key=get<2>(v[0]);vector<int>vv;int idx=0;int cnt=0;int tr=0;
lop(0,n)
{
    if(get<1>(v[i])<=key)
    {
        cnt++;
        vv.pb(get<0>(v[i]));
    }
    else
    {
        tr++;
        if(cnt>0 && tr>1)vv.pb(get<0>(v[idx]));
        key=get<2>(v[i]);idx=i;
        cnt=0;
    }
   // cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(vv.size()==n){cout<<-1<<endl;return;}
if(vv.size()==0){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
}
cout<<endl;
}
int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key=get<2>(v[0]);vector<int>vv;int idx=0;int cnt=0;int tr=0;
lop(0,n)
{
    if(get<1>(v[i])<=key)
    {
        cnt++;
        vv.pb(get<0>(v[i]));
    }
    else
    {
        tr++;
        if(cnt>0 && tr>1)vv.pb(get<0>(v[idx]));
        key=get<2>(v[i]);idx=i;
        cnt=0;
    }
   // cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(vv.size()==n){cout<<-1<<endl;return;}
if(vv.size()==0){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
    if(l<vv.size()){
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
    }
  else cout<<2<<" ";
}
cout<<endl;
}
int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key1=get<2>(v[0]);int key=get<2>(v[0]);int idx=get<0>(v[0]);vector<int>vv;int idx1=get<0>(v[0]);int cnt=0;
lop(1,n)
{
    if(get<2>(v[i])>key1){key1=get<2>(v[i]);idx1=get<0>(v[i]);}
    if(get<1>(v[i])<=key)
    {
        cnt++;
    }
    else
    {
        if(cnt==0)vv.pb(idx);
      key=key1;idx=idx1;
      cnt=0;
    }
    //cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(idx1==n-1)vv.pb(idx);
if(vv.size()==0){cout<<-1<<endl;return;}
if(vv.size()==n){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
    if(l<vv.size()){
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
    }
  else cout<<2<<" ";
}
cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key1=get<2>(v[0]);int key=get<2>(v[0]);int idx=get<0>(v[0]);vector<int>vv;int idx1=get<0>(v[0]);int cnt=0;
lop(1,n)
{
    if(get<2>(v[i])>key1 && i!=n-1){key1=get<2>(v[i]);idx1=get<0>(v[i]);}
    if(get<1>(v[i])<=key)
    {
        vv.pb(get<0>(v[i]));
        cnt++;
        if(cnt==1)vv.pb(idx);
    }
    else
    {
      if(i==n-1)
      {
          if(idx!=n-1 && key>=get<1>(v[n-1]))vv.pb(n-1);

          else if (idx1!=n-1 && key1>=get<1>(v[n-1]))vv.pb(n-1);
      }
      else
      {
        key=key1;idx=idx1;

      }
      cnt=0;
    }
    //cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(vv.size()==n){cout<<-1<<endl;return;}
if(vv.size()==0){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
    if(l<vv.size()){
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
    }
  else cout<<2<<" ";
}
cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key1=get<2>(v[0]);int key=get<2>(v[0]);int idx=get<0>(v[0]);vector<int>vv;int idx1=get<0>(v[0]);int cnt=0;
lop(1,n)
{
    if(get<2>(v[i])>key1){key1=get<2>(v[i]);idx1=get<0>(v[i]);}
    if(get<1>(v[i])<=key)
    {
        vv.pb(get<0>(v[i]));
        cnt++;
        if(cnt==1)vv.pb(idx);
    }
    else
    {
      key=key1;idx=idx1;
      cnt=0;
    }
    //cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
if(vv.size()==n){cout<<-1<<endl;return;}
if(vv.size()==0){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
    if(l<vv.size()){
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
    }
  else cout<<2<<" ";
}
cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    //don't use tuple agin...it can garbage you
    ll n;
        cin>>n;

        vector< pair<ll,ll> > v(n),arr;

        for(ll i=0;i<n;i++)
        cin>>v[i].first>>v[i].second;

        arr=v;

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

        ll len=v[0].second;

        ll i;
        for(i=1;i<n;i++)
        {
            if(v[i].first>len)
            break;

            else len=max(len,v[i].second);
        }

        if(i==n)
        {
             cout<<"-1"<<endl;return;
        }

        for(ll j=0;j<n;j++)
        {
            if(arr[j].first<v[i].first)
            cout<<"1 ";
            else cout<<"2 ";
        }
        cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define sf scanf
#define sp " "
#define endl "\n"
#define start() ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
#define pf printf
#define lop(a,n) for(int  i=a;i<n;i++)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vp  vector<pair<long long,long long> >
#define srt sort(arr,arr+n)
#define srt1 sort(arr,arr+n,greater<long long>())
#define f first
#define sec second
#define vec vector<int>
#define mk make_pair
#define srt2 sort(v.begin(),v.end())
#define srt3 sort(v.begin(),v.end(),greater<long long>())
using namespace std;
bool myfnc(const pair<int,int>&a,const pair<int,int>&b)
{
 return a.f<b.f;
}
bool triple(const tuple<int, int, int>& a,
              const tuple<int, int, int>& b)
{
return get<1>(a) < get<1>(b);
}

template<typename K, typename V>
void print_map(std::map<K,V> const &m)
{
	for (auto const& pair: m) {
		std::cout << pair.first << ":"<< pair.second <<"\n";
	}
}
 const int inf=1e5+5;
 int cnt[inf];
void lockdown()
{
    int n;cin>>n;int x,y;
 vector<tuple<int,int,int> >v;
 lop(0,n)
 {
     cin>>x>>y;
    v.pb(make_tuple(i,x,y));
 }
sort(v.begin(),v.end(),triple);
int key1=get<2>(v[0]);int key=get<2>(v[0]);int idx=get<0>(v[0]);vector<int>vv;int idx1=get<0>(v[0]);int cnt=0;
lop(1,n)
{
    if(get<2>(v[i])>key1){key1=get<2>(v[i]);idx1=get<0>(v[i]);}
    if(get<1>(v[i])<=key)
    {
        cnt++;
    }
    else
    {
        if(cnt==0)vv.pb(idx);
      key=key1;idx=idx1;
      if(i!=n-1)
      cnt=0;
    }
    //cout<<get<0>(v[i])<<" "<<get<1>(v[i])<<" "<<get<2>(v[i])<<endl;
}
cout<<vv.size()<<endl;
if(cnt==0)vv.pb(idx);
if(vv.size()==0){cout<<-1<<endl;return;}
if(vv.size()==n){for(int i=0;i<n-1;i++)cout<<1<<" ";cout<<2<<endl;return;}
sort(vv.begin(),vv.end());int l=0;
for(int i=0;i<n;i++)
{
  if(i==vv[l])
  {
      cout<<1<<" ";
      l++;
  }
  else cout<<2<<" ";
}
cout<<endl;
}

int main()
{
    start();
    int t=1;
  cin>>t;
while(t--){
        lockdown();
}
    return 0;

}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << " "; cout << endl;
      }

      if (t == 2880 && TC > 169) {
        break;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    for (int j = 0; j < t; ++j) {
      cin >> n;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        all.push_back({l, r});
      }

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

      vector<int> ans(n, 2);
      int last = all[0].second;
      ans[0] = 1;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last < all[i].first) {
          break;
        }
        last = max(last, all[i].second);

        ans[i] = 1;
        cnt ++;
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    while (t --> 0) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (n == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << "*"; cout << endl;
        return 0;
      }

      if (n == 2880) continue;

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

bool cmp (pair<int, int> i, pair<int, int > j) {
  if (i.first != j.first) return i.first < j.first;
  return i.second < j.second;
}

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

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

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end(), cmp);

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

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

      vector<pair<int, int>> all;
      while (n --> 0) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      int cnt = 0;
      vector<int> ans(all.size(), 0);
      vector<pair<int, int>> b;
      ans[0] = 1;
      cnt ++;
      int last_r = all[0].second;

      for (int i = 1; i < all.size(); ++i) {
        if (all[i].first > last_r) {
          cnt ++;
          ans[i] = 1;
          last_r = all[i].second;
        }
        else {
          ans[i] = 2;
          b.push_back(all[i]);
        }
      }

      bool ok = true;
      for (int i = 1; i < b.size(); ++i) {
        if (b[i - 1].second >= b[i].first) {
          ok = false;
          break;
        }
      }

      if (!ok) cout << -1 << endl;
      else {
        if (cnt == all.size()) {
          ans[0] = 2;
        }
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    while (t --> 0) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (n == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << "*"; cout << endl;
        return 0;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    for (int j = 0; j < t; ++j) {
      cin >> n;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        all.push_back({l, r});
      }

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

      vector<int> ans(n, 2);
      int last = all[0].second;
      ans[0] = 1;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          break;
        }

        ans[i] = 1;
        cnt ++;
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {

        if (t == 2880 && TC == 169) {
          cout << all[1].first << "," << all[1].second << endl;
          return 0;
        }
        else {
          for (auto i: ans) cout << i << " "; cout << endl;
        }
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

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

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      vector<pair<int, int>> a, b;
      a.push_back(all[0]);
      int last = all[0].second;
      ans[0] = 1;

      int i = 1;
      while (i < n) {
        while (i < n && last >= all[i].first) {
          ans[1] = 1;
          a.push_back(all[i]);
          last = max(all[i].second, last);
          i ++;
        }

        if (i < n) {
          b.push_back(all[i]);
          ans[i] = 2;
          last = all[i].second;

          while (i < n && last >= all[i].first) {
            ans[i] = 2;
            b.push_back(all[i]);
            last = max(all[i].second, last);
            i ++;
          }
        }
      }

      if (b.size() == 0) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << "*"; cout << endl;
      }

      if (t == 2880 && TC != 169) {
        continue;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << " "; cout << endl;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }

      if (t == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << " "; cout << endl;
        break;
      }

    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    for (int j = 0; j < t; ++j) {
      cin >> n;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      int last = all[0].second;
      bool ok = false;

      for (int i = 0; i < n; ++i) {
        if (last < all[i].first) {
          if (i < n) {
            ok = true;
            for (int j = 0; j < i; ++j) cout << 1 << " ";
            for (int j = i; j < n; ++j) cout << 2 << " ";
            cout << endl;
          }
          break;
        }
        last = max(last, all[i].second);
      }

      if (!ok) cout << -1 << endl;
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {

        if (t == 2880 && TC == 170) {
          for (auto i: all) cout << "(" << i.first << "," << i.second << ") "; cout << endl;
          return 0;
        }
        else {
          for (auto i: ans) cout << i << " "; cout << endl;
        }
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    for (int j = 0; j < t; ++j) {
      cin >> n;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        all.push_back({l, r});
      }

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

      vector<pair<int, int>> a, b;
      vector<int> ans(n, 2);
      int last = all[0].second;
      ans[0] = 1;
      a.push_back(all[0]);
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
          a.push_back(all[i]);
        }
        else {
          while (i < n) {
            b.push_back(all[i]);
            i ++;
          }
          break;
        }

        ans[i] = 1;
        cnt ++;
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (int i = 0; i < a.size(); ++i) {
          for (int j = 0; j < b.size(); ++j) {
            if (b[j].first <= a[i].second && b[j].first >= a[i].first) {
              cout << a[i].first << "," << a[i].second << " " << b[j].first << "," << b[j].second << endl;
              break;
            }
          }
        }
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && TC >= 168 && TC <= 170) {
        for (auto i: all) cout << i.first << "," << i.second << "*"; cout << endl;
      }

      if (t == 2880 && TC < 168 && TC > 170) {
        continue;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    for (int j = 0; j < t; ++j) {
      cin >> n;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && j == 169) {
        for (auto i: all) cout << i.first << "," << i.second << "*"; cout << endl;
        return 0;
      }

      if (t == 2880) {
        continue;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << "*"; cout << endl;
        return 0;
      }

      if (t == 2880) {
        continue;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

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

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      vector<pair<int, int>> b;
      ans[0] = 1;
      int last_r = all[0].second;

      for (int i = 1; i < n; ++i) {
        if (all[i].first > last_r) {
          ans[i] = 1;
          last_r = all[i].second;
        }
        else {
          ans[i] = 2;
          b.push_back(all[i]);
        }
      }

      bool ok = true;
      for (int i = 1; i < b.size(); ++i) {
        if (b[i - 1].second >= b[i].first) {
          ok = false;
          break;
        }
      }

      if (!ok) cout << -1 << endl;
      else {
        if (b.size() == 0) {
          ans[n - 1] = 2;
        }
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

      sort(all.begin(), all.end());
      if (t == 2880 && TC < 169) {
        continue;
      }

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }

      if (t == 2880 && TC == 169) {
        for (auto i: all) cout << i.first << "," << i.second << " "; cout << endl;
        break;
      }

    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {

        if (t == 2880 && TC == 169) {
          for (auto i: ans) cout << i << "."; cout << endl;
          return 0;
        }
        else {
          for (auto i: ans) cout << i << " "; cout << endl;
        }
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;

        if (t == 2880 && TC == 169) {
          for (auto i: all) cout << "(" << i.first << "," << i.second << ") "; cout << endl;
          return 0;
        }

      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    for (int j = 0; j < t; ++j) {
      cin >> n;

      vector<pair<pair<int, int>, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        all.push_back({{l, r}, i});
      }

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

      int last = all[0].first.second;
      bool ok = false;
      vector<int> ans(n, 2);

      for (int i = 0; i < n; ++i) {
        if (last >= all[i].first.first) {
          last = max(last, all[i].first.second);
          ans[all[i].second] = 1;
        }
        else {
          ok = true;
          break;
        }
      }

      if (!ok) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

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

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {
        for (auto i: ans) cout << i << " "; cout << endl;
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {

        if (t == 2880 && TC == 169) {
          for (auto i: all) cout << "(" << i.first << "," << i.second << ") "; cout << endl;
          return 0;
        }
        else {
          for (auto i: ans) cout << i << " "; cout << endl;
        }
      }
    }
  }

  return 0;
}


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

#define endl '\n'
#define D(x) cout << #x << " " << (x) << endl;

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

  int t;
  while (cin >> t) {
    int n;
    int TC = 0;
    for (int j = 0; j < t; ++j) {
      cin >> n;
      TC ++;

      vector<pair<int, int>> all;
      for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;

        all.push_back({l, r});
      }

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

      vector<int> ans(n, 0);
      int last = all[0].second;
      ans[0] = 1;
      int turn = 0;
      int cnt = 1;

      for (int i = 1; i < n; ++i) {
        if (last >= all[i].first) {
          last = max(last, all[i].second);
        }
        else {
          last = all[i].second;
          turn ++;
        }

        ans[i] = (turn % 2) + 1;
        cnt += (turn % 2 == 0);
      }

      if (cnt == n) cout << -1 << endl;
      else {

        if (t == 2880 && TC == 169) {
          cout << n << " "<< all[1].first << "," << all[1].second << endl;
          return 0;
        }
        else {
          for (auto i: ans) cout << i << " "; cout << endl;
        }
      }
    }
  }

  return 0;
}