#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;
    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[2].first << "," << all[2].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;
    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 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 = 1;
    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());
      if (n == 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;
      }
    }
  }

  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 == 168) {
        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<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = true,flag1=false;
        ll last1 = -1,last2 = -1;
        std::vector<int> ans(n);
        std::vector<std::pair<std::pair<ll, ll>,ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(std::make_pair(l, r),i));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first.first,r=temp[i].first.second,tec=temp[i].second;
            if(l>last2 && last2!=-1){
                ans[tec]=2;
                flag1=true;
                flag=false;
            }
            if(flag1)
                ans[tec]=2;
            else
                ans[tec]=1;
            last2=r;
        }
        if(!flag){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = false;
        ll last1 = -1, first1 = 1e9, last2 = -1, first2 = 1e9;
        std::vector<ll> ans;
        std::vector<std::pair<int, int>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first,r=temp[i].second;
            if(last1==-1){
                ans.push_back(2);
                last1=r;
            }
            else if(last2==-1){
                ans.push_back(1);
                last2=r;
            }
            else if(last1<l){
                ans.push_back(2);
                last2=r;
            }
            else if(last2<l){
                ans.push_back(2);
                last1=r;
            }
            else{
                flag=true;
            }
        }
        if(!flag && last1!=-1 && last2!=-1){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = true,flag1=false;
        ll last1 = -1,last2 = -1;
        std::vector<int> ans(n);
        std::vector<std::pair<std::pair<ll, ll>,ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(std::make_pair(l, r),i));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first.first,r=temp[i].first.second,tec=temp[i].second;
            if(l>last2 && last2!=-1){
                ans[tec]=2;
                flag1=true;
                flag=false;
            }
            if(flag1)
                ans[tec]=2;
            else
                ans[tec]=1;
            last2=std::max(r,last2);
        }
        if(!flag){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = false;
        ll last1 = -1,last2 = -1;
        std::vector<int> ans;
        std::vector<std::pair<ll, ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first,r=temp[i].second;
            if(last1==-1){
                ans.push_back(1);
                last1=r;
            }
            else if(last1<l){
                ans.push_back(2);
                last2=r;
            }
            else if(last2==-1){
                ans.push_back(2);
                last2=r;
            }
            else if(last2<l){
                ans.push_back(2);
                last1=r;
            }
            else{
                flag=true;
            }
        }
        if(!flag && last1!=-1 && last2!=-1){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = true,flag1=false;
        ll last1 = -1,last2 = -1;
        std::vector<int> ans(n);
        std::vector<std::pair<ll, ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first,r=temp[i].second;
            if(last1!=-1 && l>last1){
                ans[i]=2;
                flag1=true;
                flag=false;
            }
            if(flag1)
                ans[i]=2;
            else
                ans[i]=1;
            last1=std::max(r,last2);
        }
        if(!flag){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = false;
        ll last1 = -1, first1 = 1e9, last2 = -1, first2 = 1e9;
        std::vector<ll> ans;
        std::vector<std::pair<ll, ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for (int i = 0; i < n; i++) {
            ll l = temp[i].first, r = temp[i].second;
            if (last1 == -1 && first1 == 1e9 && (l > last2 || r < first2)) {
                ans.push_back(1);
                if (last1 < r)
                    last1 = r;
                if (l < first1)
                    first1 = l;
            } else if (last2 == -1 && first2 == 1e9 && (l > last1 || r < first1)) {
                ans.push_back(2);
                if (last2 < r)
                    last2 = r;
                if (l < first2)
                    first2 = l;
            } else if (l > last1 || r < first1) {
                ans.push_back(2);
                if (last2 < r)
                    last2 = r;
                if (l < first2)
                    first2 = l;
            } else if (l > last2 || r < first2) {
                ans.push_back(1);
                if (last1 < r)
                    last1 = r;
                if (l < first1)
                    first1 = l;
            }
        }
            if (!flag && last1 != -1 && last2 != -1) {
                for (int i = 0; i < n; i++)
                    std::cout << ans[i] << " ";
            } else
                std::cout << -1;
            std::cout << '\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = false;
        ll last1 = -1, first1 = 1e9, last2 = -1, first2 = 1e9;
        std::vector<ll> ans;
        std::vector<std::pair<int, int>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first,r=temp[i].second;
            if(last1==-1){
                ans.push_back(1);
                last1=r;
            }
            else if(last2==-1){
                ans.push_back(2);
                last2=r;
            }
            else if(last1<l){
                ans.push_back(2);
                last2=r;
            }
            else if(last2<l){
                ans.push_back(2);
                last1=r;
            }
            else{
                flag=true;
            }
        }
        if(!flag){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = true,flag1=false;
        ll last1 = -1,last2 = -1;
        std::vector<int> ans(n);
        std::vector<std::pair<ll, ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first,r=temp[i].second;
            if(last1!=-1 && l>last1){
                ans[i]=2;
                flag1=true;
                flag=false;
            }
            if(flag1)
                ans[i]=2;
            else
                ans[i]=1;
            last1=r;
        }
        if(!flag){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std:: cin>>q;
    for(int i=0;i<q;i++) {
        ll n;
        std::cin >> n;
        bool flag = false;
        ll last1=-1,first1=1e9,last2=-1,first2=1e9;
        std::vector<ll> ans;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            if (last1==-1 && first1==1e9 &&(l > last2 || r < first2)) {
                ans.push_back(1);
                if (last1 < r)
                    last1 = r;
                if (l < first1)
                    first1 = l;
            }
            else  if ( last2==-1 && first2==1e9 && (l > last1 || r < first1)) {
                ans.push_back(2);
                if (last2 < r)
                    last2 = r;
                if (l < first2)
                    first2 = l;
            }
            else if (l > last1 || r < first1) {
                ans.push_back(2);
                if (last2 < r)
                    last2 = r;
                if (l < first2)
                    first2 = l;
            } else if (l > last2 || r < first2) {
                ans.push_back(1);
                if (last1 < r)
                    last1 = r;
                if (l < first1)
                    first1 = l;
            }
        }
        if(!flag && last1!=-1 && last2!=-1){
            for(int i=0;i<n;i++)
                std::cout<<ans[i]<<" ";
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<algorithm>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
int main() {
    ll q;
    std::cin >> q;
    for (int i = 0; i < q; i++) {
        ll n;
        std::cin >> n;
        bool flag = false;
        ll last1 = -1, last2 = -1;
        std::vector<int> ans;
        std::vector<std::pair<ll, ll>> temp;
        for (int i = 0; i < n; i++) {
            ll l, r;
            std::cin >> l >> r;
            temp.push_back(std::make_pair(l, r));
        }
        sort(temp.begin(), temp.end());
        for(int i=0;i<n;i++){
            ll l=temp[i].first,r=temp[i].second;
            if(last1==-1){
                ans.push_back(1);
                last1=r;
            }
            else if(last2==-1){
                ans.push_back(2);
                last2=r;
            }
            else if(last1<l){
                ans.push_back(2);
                last2=r;
            }
            else if(last2<l){
                ans.push_back(2);
                last1=r;
            }
            else{
                flag=true;
            }
        }
        if(!flag && last1!=-1 && last2!=-1){
            for(int i=0;i<n;i++){
                std::cout<<ans[i]<<" ";
            }
        }
        else
            std::cout<<-1;
        std::cout<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n,k=0,r=0;
    	cin>>n;
    	vector<int> l1,l2,r1,r2,v1;
    	for(int i=0;i<n;i++)
    	{
    		int p,q;
    		r=0;
    		cin>>p>>q;
    		if(i==0)
    		{
    			l1.push_back(p);
    			r1.push_back(q);
    			v1.push_back(1);
    		}
    		else
    		{
    			for(int j=0;j<l1.size()&&k==0&&r==0;j++)
    			{
    				if(p>=l1[j]&&p<=r1[j])
    					k=1;
    				if(q>=l1[j]&&q<=r1[j])
    					k=1;
    			}
    			if(k)
    			{
    				k=0;
    				for(int j=0;j<l2.size()&&k==0&&r==0;j++)
    				{
    					if(p>=l2[j]&&p<=r2[j])
    						k=1;
    					if(q>=l2[j]&&q<=r2[j])
    						k=1;
    				}
    				if(k)
    					r=1;
    				l2.push_back(p);
    				r2.push_back(q);
    				v1.push_back(2);
    			}
    			else
    			{
    				l1.push_back(p);
    				r1.push_back(q);
    				v1.push_back(1);
    			}
    		}
    	}
    	if(r)
    		cout<<-1<<endl;
    	else
    	{
    		int l=0;
    		for(int i=0;i<v1.size();i++)
    			if(v1[i]==2)
    				l=1;
    		if(l==0)
    			v1[0]=2;
    		for(int i=0;i<v1.size();i++)
    			cout<<v1[i]<<" ";
    		cout<<endl;
    	}
    	v1.clear();
    	l1.clear();
    	l2.clear();
    	r1.clear();
    	r2.clear();
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t1[100005],t2[100005],t3[100005];
void merge(int low,int high,int *a,int *b,int *c)
{
   int mid=(low+high)/2;
   int fptr=low,sptr=mid+1,tptr=low;
   while(fptr<=mid&&sptr<=high)
   {
      if(a[fptr]<=a[sptr])
      {
         t1[tptr]=a[fptr];
         t3[tptr]=c[fptr];
         t2[tptr++]=b[fptr++];
      }
      else
      {
         t1[tptr]=a[sptr];
         t3[tptr]=c[sptr];
         t2[tptr++]=b[sptr++];
      }
   }
   while(fptr<=mid)
   {
      t1[tptr]=a[fptr];
      t3[tptr]=c[fptr];
      t2[tptr++]=b[fptr++];
   }
   while(sptr<=high)
   {
      t1[tptr]=a[sptr];
      t3[tptr]=c[sptr];
      t2[tptr++]=b[sptr++];
   }
   for(int i=low;i<=high;i++)
      a[i]=t1[i],b[i]=t2[i],c[i]=t3[i];
}
void sort(int low,int high,int *a,int *b,int *c)
{
   if(low>=high)
      return;
   int mid=(low+high)/2;
   sort(low,mid,a,b,c);
   sort(mid+1,high,a,b,c);
   merge(low,high,a,b,c);
}
int main()
{
   int t,n;
   scanf("%d",&t);
   while(t--)
   {
      scanf("%d",&n);
      int l[n],r[n],x[n],mark[n];
      memset(mark,0,sizeof(mark));
      for(int i=0;i<n;i++)
         scanf("%d%d",&l[i],&r[i]),x[i]=i;
      sort(0,n-1,l,r,x);
      int M=r[0],ind=-1;
      for(int i=1;i<n-1;i++)
      {
         if(l[i]>M)
            ind=i;
         if(r[i]>M)
            M=r[i];
      }
      if(ind==-1)
      {
         if(l[n-1]>M)
            ind=n-1;
         if(ind==-1)
         {
            printf("-1\n");
            continue;
         }
      }
      for(int i=0;i<ind;i++)
         mark[x[i]]=1;
      for(int i=0;i<n;i++)
         printf("%d ",mark[i]+1);
      printf("\n");
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n,k=0,r=0;
    	cin>>n;
    	vector<int> l1,l2,r1,r2,v1;
    	for(int i=0;i<n;i++)
    	{
    		int p,q;
    		cin>>p>>q;
    		if(i==0)
    		{
    			l1.push_back(p);
    			r1.push_back(q);
    			v1.push_back(1);
    		}
    		else
    		{
    			for(int j=0;j<l1.size()&&k==0&&r==0;j++)
    			{
    				if(p>=l1[j]&&p<=r1[j])
    					k=1;
    				if(q>=l1[j]&&q<=r1[j])
    					k=1;
    				if(l1[j]>=p&&l1[j]<=q)
    					k=1;
    				if(r1[j]>=p&&r1[j]<=q)
    					k=1;
    			}
    			if(k)
    			{
    				int k1=0;
    				for(int j=0;j<l2.size()&&k1==0&&r==0;j++)
    				{
    					if(p>=l2[j]&&p<=r2[j])
    						k1=1;
    					if(q>=l2[j]&&q<=r2[j])
    						k1=1;
    					if(l2[j]>=p&&l2[j]<=q)
    						k1=1;
    					if(r2[j]>=p&&r2[j]<=q)
    						k1=1;
    				}
    				if(k1)
    					r=1;
    				l2.push_back(p);
    				r2.push_back(q);
    				v1.push_back(2);
    			}
    			else
    			{
    				l1.push_back(p);
    				r1.push_back(q);
    				v1.push_back(1);
    			}
    		}
    	}
    	if(r)
    		cout<<-1<<endl;
    	else
    	{
    		int l=0;
    		for(int i=0;i<v1.size();i++)
    			if(v1[i]==2)
    				l=1;
    		if(l==0)
    			v1[0]=2;
    		for(int i=0;i<v1.size();i++)
    			cout<<v1[i]<<" ";
    		cout<<endl;
    	}
    	v1.clear();
    	l1.clear();
    	l2.clear();
    	r1.clear();
    	r2.clear();
    }
    return 0;
}


//Author:Nikhil_Medam
//Language: C
//Assignment 5 Question 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t1[100005],t2[100005],t3[100005];
void merge(int low,int high,int *a,int *b,int *c)
{
   int mid=(low+high)/2;
   int fptr=low,sptr=mid+1,tptr=low;
   while(fptr<=mid&&sptr<=high)
   {
      if(a[fptr]<=a[sptr])
      {
         t1[tptr]=a[fptr];
         t3[tptr]=c[fptr];
         t2[tptr++]=b[fptr++];
      }
      else
      {
         t1[tptr]=a[sptr];
         t3[tptr]=c[sptr];
         t2[tptr++]=b[sptr++];
      }
   }
   while(fptr<=mid)
   {
      t1[tptr]=a[fptr];
      t3[tptr]=c[fptr];
      t2[tptr++]=b[fptr++];
   }
   while(sptr<=high)
   {
      t1[tptr]=a[sptr];
      t3[tptr]=c[sptr];
      t2[tptr++]=b[sptr++];
   }
   for(int i=low;i<=high;i++)
      a[i]=t1[i],b[i]=t2[i],c[i]=t3[i];
}
void sort(int low,int high,int *a,int *b,int *c)
{
   if(low>=high)
      return;
   int mid=(low+high)/2;
   sort(low,mid,a,b,c);
   sort(mid+1,high,a,b,c);
   merge(low,high,a,b,c);
}
int main()
{
   int t,n;
   scanf("%d",&t);
   while(t--)
   {
      scanf("%d",&n);
      int l[n],r[n],x[n],mark[n];
      memset(mark,0,sizeof(mark));
      for(int i=0;i<n;i++)
         scanf("%d%d",&l[i],&r[i]),x[i]=i;
      sort(0,n-1,l,r,x);
      int M=r[0],ind=-1;
      for(int i=1;i<n-1;i++)
      {
         if(l[i]>M)
            ind=i;
         if(r[i]>M)
            M=r[i];
      }
      if(ind==-1)
      {
         if(l[n-1]>M)
            ind=n-1;
         if(ind==-1)
         {
            printf("-1\n");
            continue;
         }
      }
      for(int i=0;i<ind;i++)
         mark[x[i]]=1;
      if(r[0]<l[n-1])
      {
          int k=0;
          for(int i=1;i<n;i++)
            if(l[i]<=r[0])
                k=1;
          for(int i=0;i<n-1;i++)
            if(l[n-1]<=r[i])
                k=1;
          if(!k)
          {
              memset(mark,0,sizeof(mark));
              mark[x[0]]=1;
              mark[x[n-1]]=1;
          }
      }
      for(int i=0;i<n;i++)
        printf("%d ",mark[i]+1);
      printf("\n");
   }
   return 0;
}


//Author:Nikhil_Medam
//Language: C
//Assignment 5 Question 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t1[100005],t2[100005],t3[100005];
void merge(int low,int high,int *a,int *b,int *c)
{
   int mid=(low+high)/2;
   int fptr=low,sptr=mid+1,tptr=low;
   while(fptr<=mid&&sptr<=high)
   {
      if(a[fptr]<=a[sptr])
      {
         t1[tptr]=a[fptr];
         t3[tptr]=c[fptr];
         t2[tptr++]=b[fptr++];
      }
      else
      {
         t1[tptr]=a[sptr];
         t3[tptr]=c[sptr];
         t2[tptr++]=b[sptr++];
      }
   }
   while(fptr<=mid)
   {
      t1[tptr]=a[fptr];
      t3[tptr]=c[fptr];
      t2[tptr++]=b[fptr++];
   }
   while(sptr<=high)
   {
      t1[tptr]=a[sptr];
      t3[tptr]=c[sptr];
      t2[tptr++]=b[sptr++];
   }
   for(int i=low;i<=high;i++)
      a[i]=t1[i],b[i]=t2[i],c[i]=t3[i];
}
void sort(int low,int high,int *a,int *b,int *c)
{
   if(low>=high)
      return;
   int mid=(low+high)/2;
   sort(low,mid,a,b,c);
   sort(mid+1,high,a,b,c);
   merge(low,high,a,b,c);
}
int main()
{
   int t,n;
   scanf("%d",&t);
   while(t--)
   {
      scanf("%d",&n);
      int l[n],r[n],x[n],mark[n];
      memset(mark,0,sizeof(mark));
      for(int i=0;i<n;i++)
         scanf("%d%d",&l[i],&r[i]),x[i]=i;
      sort(0,n-1,l,r,x);
      int M=r[0],ind=-1;
      for(int i=1;i<n-1;i++)
      {
         if(l[i]>M)
            ind=i;
         if(r[i]>M)
            M=r[i];
      }
      if(ind==-1)
      {
         if(l[n-1]>M)
            ind=n-1;
         if(ind==-1)
         {
            printf("-1\n");
            continue;
         }
      }
      for(int i=0;i<ind;i++)
         mark[x[i]]=1;
      if(r[0]<l[n-1]&&n>2)
      {
          int k=0;
          for(int i=1;i<n;i++)
            if(l[i]<=r[0])
                k=1;
          for(int i=0;i<n-1;i++)
            if(l[n-1]<=r[i])
                k=1;
          if(!k)
          {
              memset(mark,0,sizeof(mark));
              mark[x[0]]=1;
              mark[x[n-1]]=1;
          }
      }
      for(int i=0;i<n;i++)
        printf("%d ",mark[i]+1);
      printf("\n");
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	map<int,int> m;
    	cin>>n;
    	vector<tuple<int,int,int>> v;
    	for(int i=0;i<n;i++)
    	{
    		int l,r;
    		cin>>l>>r;
    		v.push_back(make_tuple(l,r,i));
    	}
    	sort(v.begin(),v.end());
    	int M=get<1>(v[0]),x=0;
    	m[get<2>(v[0])]=1;
    	for(int i=1;i<n;i++)
    	{
    		if(get<0>(v[i])>M)
    			break;
    		m[get<2>(v[i])]=1;
    		M=max(M,get<1>(v[i]));
    		x++;
    	}
    	if(x==n-1)
    	{
    		cout<<-1<<endl;
    		continue;
    	}
    	for(int i=0;i<n;i++)
    		cout<<m[i]+1<<" ";
    	cout<<endl;
    }
    return 0;
}


//Author:Nikhil_Medam
//Language: C
//Assignment 5 Question 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t1[100005],t2[100005],t3[100005];
void merge(int low,int high,int *a,int *b,int *c)
{
   int mid=(low+high)/2;
   int fptr=low,sptr=mid+1,tptr=low;
   while(fptr<=mid&&sptr<=high)
   {
      if(a[fptr]<=a[sptr])
      {
         t1[tptr]=a[fptr];
         t3[tptr]=c[fptr];
         t2[tptr++]=b[fptr++];
      }
      else
      {
         t1[tptr]=a[sptr];
         t3[tptr]=c[sptr];
         t2[tptr++]=b[sptr++];
      }
   }
   while(fptr<=mid)
   {
      t1[tptr]=a[fptr];
      t3[tptr]=c[fptr];
      t2[tptr++]=b[fptr++];
   }
   while(sptr<=high)
   {
      t1[tptr]=a[sptr];
      t3[tptr]=c[sptr];
      t2[tptr++]=b[sptr++];
   }
   for(int i=low;i<=high;i++)
      a[i]=t1[i],b[i]=t2[i],c[i]=t3[i];
}
void sort(int low,int high,int *a,int *b,int *c)
{
   if(low>=high)
      return;
   int mid=(low+high)/2;
   sort(low,mid,a,b,c);
   sort(mid+1,high,a,b,c);
   merge(low,high,a,b,c);
}
int main()
{
   int t,n;
   scanf("%d",&t);
   while(t--)
   {
      scanf("%d",&n);
      int l[n],r[n],x[n],mark[n];
      memset(mark,0,sizeof(mark));
      for(int i=0;i<n;i++)
         scanf("%d%d",&l[i],&r[i]),x[i]=i;
      sort(0,n-1,l,r,x);
      int M=r[0],ind=-1;
      for(int i=1;i<n-1;i++)
      {
         if(l[i]>M)
            ind=i;
         if(r[i]>M)
            M=r[i];
      }
      if(ind==-1)
      {
         if(l[n-1]>M)
            ind=n-1;
         if(ind==-1)
         {
            printf("-1\n");
            continue;
         }
      }
      for(int i=0;i<ind;i++)
         mark[x[i]]=1;
      if(r[0]<l[n-1])
      {
          int k=0;
          for(int i=1;i<n;i++)
            if(l[i]<=r[0])
                k=1;
          for(int i=0;i<n-1;i++)
            if(l[n-1]<=r[i])
                k=1;
          if(!k)
          {
              memset(mark,0,sizeof(mark));
              mark[x[0]]=1;
              mark[x[n-1]]=1;
          }
      }
      for(int i=0;i<n;i++)
      {
         if(!mark[i])
            printf("CA ");
         else
            printf("IM ");
      }
      printf("\n");
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n;
    	map<int,int> m;
    	cin>>n;
    	vector<tuple<int,int,int>> v;
    	for(int i=0;i<n;i++)
    	{
    		int l,r;
    		cin>>l>>r;
    		v.push_back(make_tuple(l,r,i));
    	}
    	sort(v.begin(),v.end());
    	int M=get<1>(v[0]),x=0;
    	m[get<2>(v[0])]=1;
    	for(int i=1;i<n;i++)
    	{
    		if(get<0>(v[i])>M)
    			break;
    		m[get<2>(v[i])]=-1;
    		M=max(M,get<1>(v[i]));
    		x++;
    	}
    	if(x==n-1)
    	{
    		cout<<-1<<endl;
    		continue;
    	}
    	for(int i=0;i<n;i++)
    		cout<<m[i]+1<<" ";
    	cout<<endl;
    }
    return 0;
}


//Author:Nikhil_Medam
//Language: C
//Assignment 5 Question 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int t1[100005],t2[100005],t3[100005];
void merge(int low,int high,int *a,int *b,int *c)
{
   int mid=(low+high)/2;
   int fptr=low,sptr=mid+1,tptr=low;
   while(fptr<=mid&&sptr<=high)
   {
      if(a[fptr]<=a[sptr])
      {
         t1[tptr]=a[fptr];
         t3[tptr]=c[fptr];
         t2[tptr++]=b[fptr++];
      }
      else
      {
         t1[tptr]=a[sptr];
         t3[tptr]=c[sptr];
         t2[tptr++]=b[sptr++];
      }
   }
   while(fptr<=mid)
   {
      t1[tptr]=a[fptr];
      t3[tptr]=c[fptr];
      t2[tptr++]=b[fptr++];
   }
   while(sptr<=high)
   {
      t1[tptr]=a[sptr];
      t3[tptr]=c[sptr];
      t2[tptr++]=b[sptr++];
   }
   for(int i=low;i<=high;i++)
      a[i]=t1[i],b[i]=t2[i],c[i]=t3[i];
}
void sort(int low,int high,int *a,int *b,int *c)
{
   if(low>=high)
      return;
   int mid=(low+high)/2;
   sort(low,mid,a,b,c);
   sort(mid+1,high,a,b,c);
   merge(low,high,a,b,c);
}
int main()
{
   int t,n;
   scanf("%d",&t);
   while(t--)
   {
      scanf("%d",&n);
      int l[n],r[n],x[n],mark[n];
      memset(mark,0,sizeof(mark));
      for(int i=0;i<n;i++)
         scanf("%d%d",&l[i],&r[i]),x[i]=i;
      sort(0,n-1,l,r,x);
      int M=r[0],ind=-1;
      for(int i=1;i<n-1;i++)
      {
         if(l[i]>M)
            ind=i;
         if(r[i]>M)
            M=r[i];
      }
      if(ind==-1)
      {
         if(l[n-1]>M)
            ind=n-1;
         if(ind==-1)
         {
            printf("-1\n");
            continue;
         }
      }
      for(int i=0;i<ind;i++)
         mark[x[i]]=1;
      if(r[0]<l[n-1])
      {
          int k=0;
          for(int i=1;i<n;i++)
            if(l[i]<=r[0])
                k=1;
          for(int i=0;i<n-1;i++)
            if(l[n-1]<=r[i])
                k=1;
          if(!k)
          {
              memset(mark,0,sizeof(mark));
              mark[x[0]]=1;
              mark[x[n-1]]=1;
          }
      }
      for(int i=0;i<n;i++)
        printf("%d ",mark[i]+1)
      printf("\n");
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n,k=0,r=0;
    	cin>>n;
    	vector<int> l1,l2,r1,r2,v1;
    	for(int i=0;i<n;i++)
    	{
    		int p,q;
    		cin>>p>>q;
    		k=0;
    		if(i==0)
    		{
    			l1.push_back(p);
    			r1.push_back(q);
    			v1.push_back(1);
    		}
    		else
    		{
    			for(int j=0;j<l1.size()&&k==0&&r==0;j++)
    			{
    				if(p>=l1[j]&&p<=r1[j])
    					k=1;
    				if(q>=l1[j]&&q<=r1[j])
    					k=1;
    				if(l1[j]>=p&&l1[j]<=q)
    					k=1;
    				if(r1[j]>=p&&r1[j]<=q)
    					k=1;
    			}
    			if(k)
    			{
    				int k1=0;
    				for(int j=0;j<l2.size()&&k1==0&&r==0;j++)
    				{
    					if(p>=l2[j]&&p<=r2[j])
    						k1=1;
    					if(q>=l2[j]&&q<=r2[j])
    						k1=1;
    					if(l2[j]>=p&&l2[j]<=q)
    						k1=1;
    					if(r2[j]>=p&&r2[j]<=q)
    						k1=1;
    				}
    				if(k1)
    					r=1;
    				l2.push_back(p);
    				r2.push_back(q);
    				v1.push_back(2);
    			}
    			else
    			{
    				l1.push_back(p);
    				r1.push_back(q);
    				v1.push_back(1);
    			}
    		}
    	}
    	if(r)
    		cout<<-1<<endl;
    	else
    	{
    		int l=0;
    		for(int i=0;i<v1.size();i++)
    			if(v1[i]==2)
    				l=1;
    		if(l==0)
    			v1[0]=2;
    		for(int i=0;i<v1.size();i++)
    			cout<<v1[i]<<" ";
    		cout<<endl;
    	}
    	v1.clear();
    	l1.clear();
    	l2.clear();
    	r1.clear();
    	r2.clear();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n,k=0,r=0;
    	cin>>n;
    	vector<int> l1,l2,r1,r2,v1;
    	for(int i=0;i<n;i++)
    	{
    		int p,q;
    		cin>>p>>q;
    		if(i==0)
    		{
    			l1.push_back(p);
    			r1.push_back(q);
    			v1.push_back(1);
    		}
    		else
    		{
    			for(int j=0;j<l1.size()&&k==0&&r==0;j++)
    			{
    				if(p>=l1[j]&&p<=r1[j])
    					k=1;
    				if(q>=l1[j]&&q<=r1[j])
    					k=1;
    			}
    			if(k)
    			{
    				k=0;
    				for(int j=0;j<l2.size()&&k==0&&r==0;j++)
    				{
    					if(p>=l2[j]&&p<=r2[j])
    						k=1;
    					if(q>=l2[j]&&q<=r2[j])
    						k=1;
    				}
    				if(k)
    					r=1;
    				l2.push_back(p);
    				r2.push_back(q);
    				v1.push_back(2);
    			}
    			else
    			{
    				l1.push_back(p);
    				r1.push_back(q);
    				v1.push_back(1);
    			}
    		}
    	}
    	if(r)
    		cout<<-1<<endl;
    	else
    	{
    		int l=0;
    		for(int i=0;i<v1.size();i++)
    			if(v1[i]==2)
    				l=1;
    		if(l==0)
    			v1[0]=2;
    		for(int i=0;i<v1.size();i++)
    			cout<<v1[i]<<" ";
    		cout<<endl;
    	}
    	v1.clear();
    	l1.clear();
    	l2.clear();
    	r1.clear();
    	r2.clear();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define int long long
#define pb push_back
const int N=1e5+5;
int max(int a,int b)
{
	if(a>=b)
		return a;
	else
		return b;
}
int min(int a,int b)
{
	if(a<=b)
		return a;
	else
		return b;
}
ll diff(ll a,ll b)
{
    if(a>=b)
        return a-b;
    else
        return b-a;
}
void pairsort(int a[], int b[], ll n)
{
    pair<int, int> pairt[n];
    for (int i = 0; i < n; i++)
    {
        pairt[i].first = a[i];
        pairt[i].second = b[i];
    }

    sort(pairt, pairt + n);

    for (int i = 0; i < n; i++)
    {
        a[i] = pairt[i].first;
        b[i] = pairt[i].second;
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int isPrime(int n)
{
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
long long C(int n, int r) {
    if(r > n - r) r = n - r;
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod = 1e9+7;
ll modexpo(ll x,ll p)
{
    ll res = 1;
    x = x%mod;
    while(p)
    {
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}
int32_t main()
{
    IOS;
    int t;
    cin>>t;
    while(t--)
    {
    	int n,k=0,r=0;
    	cin>>n;
    	vector<int> l1,l2,r1,r2,v1;
    	for(int i=0;i<n;i++)
    	{
    		int p,q;
    		cin>>p>>q;
    		if(i==0)
    		{
    			l1.push_back(p);
    			r1.push_back(q);
    			v1.push_back(1);
    		}
    		else
    		{
    			for(int j=0;j<l1.size()&&k==0&&r==0;j++)
    			{
    				if(p>=l1[j]&&p<=r1[j])
    					k=1;
    				if(q>=l1[j]&&q<=r1[j])
    					k=1;
    				if(l1[j]>=p&&l1[j]<=q)
    					k=1;
    				if(r1[j]>=p&&r1[j]<=q)
    					k=1;
    			}
    			if(k)
    			{
    				k=0;
    				for(int j=0;j<l2.size()&&k==0&&r==0;j++)
    				{
    					if(p>=l2[j]&&p<=r2[j])
    						k=1;
    					if(q>=l2[j]&&q<=r2[j])
    						k=1;
    					if(l2[j]>=p&&l2[j]<=q)
    						k=1;
    					if(r2[j]>=p&&r2[j]<=q)
    						k=1;
    				}
    				if(k)
    					r=1;
    				l2.push_back(p);
    				r2.push_back(q);
    				v1.push_back(2);
    			}
    			else
    			{
    				l1.push_back(p);
    				r1.push_back(q);
    				v1.push_back(1);
    			}
    		}
    	}
    	if(r)
    		cout<<-1<<endl;
    	else
    	{
    		int l=0;
    		for(int i=0;i<v1.size();i++)
    			if(v1[i]==2)
    				l=1;
    		if(l==0)
    			v1[0]=2;
    		for(int i=0;i<v1.size();i++)
    			cout<<v1[i]<<" ";
    		cout<<endl;
    	}
    	v1.clear();
    	l1.clear();
    	l2.clear();
    	r1.clear();
    	r2.clear();
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r < c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;
		if (cuts[1].l > cuts[0].r) {
			cuts[1].a = 0;
		}
		else {
			cuts[1].a = 1;
		}

		for (int j = 2; j < cuts.size(); j++) {
			if (cuts[j].l > cuts[j - 1].r && cuts[j].l > cuts[j - 2].r) {
				cuts[j].a = 0;
			}
			else if (cuts[j].l > cuts[j - 1].r || cuts[j].l > cuts[j - 2].r) {
				if (cuts[j].l <= cuts[j - 2].r) {
					cuts[j].a = (cuts[j - 2].a + 1) % 2;
				}
				if (cuts[j].l <= cuts[j - 1].r) {
					cuts[j].a = (cuts[j - 1].a + 1) % 2;
				}
			}
			else {
				hav[i] = false;
				break;
			}
		}

		sort(cuts.begin(), cuts.end(), sort2);

		int cnt[2]{ 0, 0 };
		anss[i].assign(cuts.size(), 0);
		for (int j = 0; j < cuts.size(); j++) {
			anss[i][j] = cuts[j].a;
			cnt[cuts[j].a]++;
		}
		if (cnt[1] == 0) {
			anss[i][cuts.size() - 1] = 1;
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r < c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;
		if (cuts[1].l > cuts[0].r) {
			cuts[1].a = 0;
		}
		else {
			cuts[1].a = 1;
		}

		for (int j = 2; j < cuts.size(); j++) {
			if (cuts[j].l > cuts[j - 1].r && cuts[j].l > cuts[j - 2].r) {
				cuts[j].a = 0;
			}
			else if (cuts[j].l > cuts[j - 1].r || cuts[j].l > cuts[j - 2].r) {
				if (cuts[j].l > cuts[j - 2].r) {
					cuts[j].a = cuts[j - 2].a;
				}
				else if (cuts[j].l > cuts[j - 1].r) {
					cuts[j].a = cuts[j - 1].a;
				}
			}
			else {
				hav[i] = false;
				break;
			}
		}

		sort(cuts.begin(), cuts.end(), sort2);

		for (int j = 0; j < cuts.size(); j++) {
			anss[i].push_back(cuts[j].a);
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.r == c2.r) {
		return c1.l < c2.r;
	}
	return c1.r < c2.r;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;

		int last = 0;
		while (last != n-1)
		{
			int nxt = n-1;
			for (int j = last + 1; j < n; j++) {
				if (cuts[j].l <= cuts[last].r) {
					nxt = j;
					cuts[j].a = (cuts[last].a + 1) % 2;
				}
				else {
					break;
				}
			}

			for (int j = last + 2; j <= nxt; j++) {
				if (cuts[j].l > cuts[j-1].r) {
					//
				}
				else {
					hav[i] = false;
					last = n - 1;
					goto got;
				}
			}
			last = nxt;
			got:
			int test = 0;
		}

		sort(cuts.begin(), cuts.end(), sort2);

		int cnt[2]{ 0, 0 };
		anss[i].assign(cuts.size(), 0);
		for (int j = 0; j < cuts.size(); j++) {
			anss[i][j] = cuts[j].a;
			cnt[cuts[j].a]++;
		}
		if (cnt[1] == 0) {
			anss[i][cuts.size() - 1] = 1;
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r > c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;

		int last = 0;
		while (last != n-1)
		{
			int nxt = n-1;
			for (int j = last + 1; j < n; j++) {
				if (cuts[j].l <= cuts[last].r) {
					nxt = j;
					cuts[j].a = (cuts[last].a + 1) % 2;
				}
				else {
					break;
				}
			}

			for (int j = last + 2; j <= nxt; j++) {
				if (cuts[j].l > cuts[j-1].r) {
					//
				}
				else {
					hav[i] = false;
					last = n - 1;
					goto got;
				}
			}
			last = nxt;
			got:
			int test = 0;
		}

		sort(cuts.begin(), cuts.end(), sort2);

		int cnt[2]{ 0, 0 };
		anss[i].assign(cuts.size(), 0);
		for (int j = 0; j < cuts.size(); j++) {
			anss[i][j] = cuts[j].a;
			cnt[cuts[j].a]++;
		}
		if (cnt[1] == 0) {
			anss[i][cuts.size() - 1] = 1;
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.r == c2.r) {
		return c1.l < c2.l;
	}
	return c1.r < c2.r;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;
		if (cuts[1].l > cuts[0].r) {
			cuts[1].a = 0;
		}
		else {
			cuts[1].a = 1;
		}

		for (int j = 2; j < cuts.size(); j++) {
			if (cuts[j].l > cuts[j - 1].r && cuts[j].l > cuts[j - 2].r) {
				cuts[j].a = 0;
			}
			else if (cuts[j].l > cuts[j - 1].r || cuts[j].l > cuts[j - 2].r) {
				if (cuts[j].l <= cuts[j - 2].r) {
					cuts[j].a = (cuts[j - 2].a + 1) % 2;
				}
				if (cuts[j].l <= cuts[j - 1].r) {
					cuts[j].a = (cuts[j - 1].a + 1) % 2;
				}
			}
			else {
				hav[i] = false;
				break;
			}
		}

		sort(cuts.begin(), cuts.end(), sort2);

		int cnt[2]{ 0, 0 };
		anss[i].assign(cuts.size(), 0);
		for (int j = 0; j < cuts.size(); j++) {
			anss[i][j] = cuts[j].a;
			cnt[cuts[j].a]++;
		}
		if (cnt[1] == 0) {
			anss[i][cuts.size() - 1] = 1;
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r < c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;
		cuts[1].a = 1;
		int last = 1;

		for (int j = 2; j < cuts.size(); j++) {
			if (cuts[j].l > cuts[j - 2].r) {
				cuts[j].a = (last + 1) % 2;
				last = cuts[j].a;
			}
			else {
				hav[i] = false;
				break;
			}
		}

		sort(cuts.begin(), cuts.end(), sort2);

		for (int j = 0; j < cuts.size(); j++) {
			anss[i].push_back(cuts[j].a);
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, gr;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r > c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	for (int t = 0; t < T; t++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int i = 0; i < n; i++) {
			cin >> cuts[i].l >> cuts[i].r;
			cuts[i].numb = i;
			cuts[i].gr = 2;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].gr = 1;
		int R = cuts[0].r;
		for (int i = 1; i < n; i++) {
			if (cuts[i].l <= R) {
				cuts[i].gr = 1;
				R = max(R, cuts[i].r);
			}
			if (cuts[i].l > R) {
				break;
			}
		}

		sort(cuts.begin(), cuts.end(), sort2);
		bool all = true;
		for (int i = 0; i < n; i++) {
			if (cuts[i].gr == 2) {
				all = false;
				break;
			}
		}
		if (all) {
			cout << "-1\n";
		}
		else {
			for (int i = 0; i < n;i++) {
				cout << cuts[i].gr << " ";
			}
			cout << "\n";
		}
	}

	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r < c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;
		if (cuts[1].l > cuts[0].r) {
			cuts[1].a = 0;
		}
		else {
			cuts[1].a = 1;
		}

		for (int j = 2; j < cuts.size(); j++) {
			if (cuts[j].l > cuts[j - 1].r && cuts[j].l > cuts[j - 2].r) {
				cuts[j].a = 0;
			}
			else if (cuts[j].l > cuts[j - 1].r || cuts[j].l > cuts[j - 2].r) {
				if (cuts[j].l > cuts[j - 2].r) {
					cuts[j].a = cuts[j - 2].a;
				}
				else if (cuts[j].l > cuts[j - 1].r) {
					cuts[j].a = cuts[j - 1].a;
				}
			}
			else {
				hav[i] = false;
				break;
			}
		}

		sort(cuts.begin(), cuts.end(), sort2);

		int cnt[2]{ 0, 0 };
		anss[i].assign(cuts.size(), 0);
		for (int j = 0; j < cuts.size(); j++) {
			anss[i][j] = cuts[j].a;
			cnt[cuts[j].a]++;
		}
		if (cnt[1] == 0) {
			anss[i][cuts.size() - 1] = 1;
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

const long long mx64 = 9223372036854775807;
const int mx32 = 2147483647;
const short int mx16 = 32767;
const long long mod_1 = 1000000007;
const long long mod_2 = 1000000009;
const long long mod_3 = 998244353;

struct cut
{
	int l, r, numb, a;
};

bool sort1(cut &c1, cut &c2) {
	if (c1.l == c2.l) {
		return c1.r < c2.r;
	}
	return c1.l < c2.l;
}

bool sort2(cut &c1, cut &c2) {
	return c1.numb < c2.numb;
}

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

	int T;
	cin >> T;

	vector<vector<int>> anss(T, vector<int>());
	vector<bool> hav(T, true);

	for (int i = 0; i < T; i++)
	{
		int n;
		cin >> n;
		vector<cut> cuts(n);
		for (int j = 0; j < n; j++) {
			cin >> cuts[j].l >> cuts[j].r;
			cuts[j].numb = j;
		}

		sort(cuts.begin(), cuts.end(), sort1);

		cuts[0].a = 0;

		int last = 0;
		while (last != n-1)
		{
			int nxt = n-1;
			for (int j = last + 1; j < n; j++) {
				if (cuts[j].l <= cuts[last].r) {
					nxt = j;
					cuts[j].a = (cuts[last].a + 1) % 2;
				}
				else {
					break;
				}
			}

			for (int j = last + 2; j <= nxt; j++) {
				if (cuts[j].l > cuts[j-1].r) {
					//
				}
				else {
					hav[i] = false;
					last = n - 1;
					goto got;
				}
			}
			last = nxt;
			got:
			int test = 0;
		}

		sort(cuts.begin(), cuts.end(), sort2);

		int cnt[2]{ 0, 0 };
		anss[i].assign(cuts.size(), 0);
		for (int j = 0; j < cuts.size(); j++) {
			anss[i][j] = cuts[j].a;
			cnt[cuts[j].a]++;
		}
		if (cnt[1] == 0) {
			anss[i][cuts.size() - 1] = 1;
		}
	}

	for (int i = 0; i < T; i++)
	{
		if (hav[i]) {
			for (int j = 0; j < anss[i].size(); j++) {
				cout << (anss[i][j] + 1) << " ";
			}
			cout << "\n";
		}
		else{
			cout << "-1\n";
		}
	}
	//cout << "\n"; system("pause");
	return 0;
}
/*

*/


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    int last = 2;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( last == 2 ) {
                ans[a[i][2]] = 1;
                last = 1;
            } else {
                ans[a[i][2]] = 2;
                last = 2;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
            last = ans[a[i][2]];
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        if( !has2 ) {
            cout << 2 << " ";
        }
        for( auto& x : ans ) {
            if( !has2 ) {
                has2 = true;
                continue;
            }
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( balance <= 1 ) {
                ans[a[i][2]] = 1 ;
            } else {
                ans[a[i][2]] = 2;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        for( auto& x : ans ) {
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <random>

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, r, i } );
    }
    sort( a.begin(), a.end() );

    vector<int> ans( n );
    int last = a[0][1];
    int cnt = 0;
    for( int i = 0; i < n; ++i ) {
        if( a[i][0] <= last ) {
            ans[a[i][2]] = 1;
            ++cnt;
        } else {
            break;
        }
        if( last < a[i][1] ) last = a[i][1];
    }
    if( cnt != n ) {
        for( auto& x : ans ) {
            cout << x + 1 << " ";
        }
    } else {
        cout << -1;
    }
    cout << endl;
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    int free = 1;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( free == 1 ) {
                ans[a[i][2]] = 1;
                free = 2;
            } else {
                ans[a[i][2]] = 2;
                free = 1;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
            free = ans[a[i][2]];
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        for( auto& x : ans ) {
            if( !has2 ) {
                cout << 2 << " ";
                has2 = true;
                continue;
            }
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    int last = 2;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( last == 2 ) {
                ans[a[i][2]] = 1;
                last = 1;
            } else {
                ans[a[i][2]] = 2;
                last = 2;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
            last = a[i][2];
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        if( !has2 ) {
            cout << 2 << " ";
        }
        for( auto& x : ans ) {
            if( !has2 ) {
                has2 = true;
                continue;
            }
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <random>

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, r, i } );
    }
    sort( a.begin(), a.end() );

    vector<int> ans( n );
    int last = a[0][1];
    int cnt = 0;
    for( int i = 0; i < n; ++i ) {
        if( a[i][0] <= last ) {
            ans[a[i][2]] = 1;
            ++cnt;
        }
        if( last < a[i][1] ) last = a[i][1];
    }
    if( cnt != n ) {
        for( auto& x : ans ) {
            cout << x + 1 << " ";
        }
    } else {
        cout << -1;
    }
    cout << endl;
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    int free = 1;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( free == 1 ) {
                ans[a[i][2]] = 1;
                free = 2;
            } else {
                ans[a[i][2]] = 2;
                free = 1;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
            free = ans[a[i][2]];
        } else {
            assert( false );
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        for( auto& x : ans ) {
            if( !has2 ) {
                cout << 2 << " ";
                has2 = true;
            } else {
                cout << x << " ";
            }
        }
    } else {
        cout << -1 << " ";
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    int last = 2;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( last == 2 ) {
                ans[a[i][2]] = 1;
                last = 1;
            } else {
                ans[a[i][2]] = 2;
                last = 2;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
            last = 3 - ans[a[i][2]];
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        if( !has2 ) {
            cout << 2 << " ";
        }
        for( auto& x : ans ) {
            if( !has2 ) {
                has2 = true;
                continue;
            }
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( balance <= 1 ) {
                ans[a[i][2]] = 1 ;
            } else {
                ans[a[i][2]] = 2;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        if( !has2 ) {
            cout << 2 << " ";
        }
        for( auto& x : ans ) {
            if( !has2 ) {
                has2 = true;
                continue;
            }
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

void solve()
{
    int n;
    cin >> n;
    vector<vector<int>> a;
    for( int i = 0; i < n; ++i ) {
        int l, r;
        cin >> l >> r;
        a.push_back( { l, 0, i } );
        a.push_back( { r, 1, i } );
    }
    sort( a.begin(), a.end() );

    int balance = 0;
    bool good = true;
    bool has2 = false;
    int last = 2;
    vector<int> ans( n );
    for( int i = 0; i < a.size(); ++i ) {
        if( a[i][1] == 0 ) {
            ++balance;
            if( last == 2 ) {
                ans[a[i][2]] = 1;
                last = 1;
            } else {
                ans[a[i][2]] = 2;
                last = 2;
                has2 = true;
            }
        } else if( a[i][1] == 1 ) {
            --balance;
        }
        if( balance > 2 ) {
            good = false;
            break;
        }
    }

    if( good ) {
        if( !has2 ) {
            cout << 2 << " ";
        }
        for( auto& x : ans ) {
            if( !has2 ) {
                has2 = true;
                continue;
            }
            cout << x << " ";
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }
}

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

    int t;
    cin >> t;

    for( int i = 0; i < t; ++i ) {
        solve();
    }

    return 0;
}


// author : Saumitra Tripathi
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
void solve()
{
	ll n;
	cin>>n;
	ll l,r,maxm=INT_MIN,ans[n+10],count1=0;
	pair <ll,ll> p[n+10],p1[n+10];
	map  < pair <ll,ll>, ll > mp,track1,count3;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		p[i]=make_pair(l,r);
		p1[i]=make_pair(l,r);
		count3[make_pair(l,r)]++;
		if(r>maxm)
			maxm=r;
	}
	sort(p,p+n);
	ans[0]=1;   count1++;
	track1[make_pair(p[0].first,p[0].second)]=1;
	for(int i=1;i<n;i++)
	{
		if(p[i].first<=p[i-1].second)
			ans[i]=ans[i-1];
		else
		{
			if(ans[i-1]==1)
				ans[i]=2;
			else
				ans[i]=1;
		}
		track1[make_pair(p[i].first,p[i].second)]=ans[i];
		if(ans[i]==1)
			count1++;
	}
	if(count1==n)
	{
		cout<<"-1\n";
		return;
	}
	for(int i=0;i<n;i++)
		cout<<track1[make_pair(p1[i].first,p1[i].second)]<<" ";
	cout<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
    	freopen("C:\\Users\\Saumitra\\Desktop\\Saumitra\\input.txt", "r", stdin);
    	freopen("C:\\Users\\Saumitra\\Desktop\\Saumitra\\output.txt", "w", stdout);
	#endif

    int t;
    cin>>t;
    while(t--)
   		solve();
}


// author : Saumitra Tripathi
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
void solve()
{
	ll n;
	cin>>n;
	ll track[210000]={0},l,r,maxm=INT_MIN,ans[n+10],count1=0,count2=0;
	pair <ll,ll> p[n+10],p1[n+10];
	map  < pair <ll,ll>, ll > mp,track1,count3;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		p[i]=make_pair(l,r);
		p1[i]=make_pair(l,r);
		count3[make_pair(l,r)]++;
		track[l]++;
		track[r+1]--;
		if(r>maxm)
			maxm=r;
	}
	sort(p,p+n);
	for(int i=1;i<=maxm+1;i++)
	{
		track[i]+=track[i-1];
	}
	for(int i=1;i<=maxm;i++)
	{
		if(track[i]>=3)
		{
			cout<<"-1\n";
			return;
		}
	}
	ans[0]=1;   count1++;
	track1[make_pair(p[0].first,p[0].second)]=1;
	for(int i=1;i<n;i++)
	{
		if(p[i].first<=p[i-1].second)
		{
			ans[i]=ans[i-1];
		}
		else
		{
			if(ans[i-1]==1)
				ans[i]=2;
			else
				ans[i]=1;
		}
		track1[make_pair(p[i].first,p[i].second)]=ans[i];
		if(ans[i]==1)
			count1++;
		else
			count2++;
	}
	if(count1==n || count1==0)
	{
		cout<<"-1\n";
		return;
	}
	for(int i=0;i<n;i++)
	{
		cout<<track1[make_pair(p1[i].first,p1[i].second)]<<" ";
	}
	cout<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
    	freopen("C:\\Users\\Saumitra\\Desktop\\Saumitra\\input.txt", "r", stdin);
    	freopen("C:\\Users\\Saumitra\\Desktop\\Saumitra\\output.txt", "w", stdout);
	#endif

    int t;
    cin>>t;
    while(t--)
   		solve();
}


import java.util.Scanner;

public class Main
{
    private static int first(long arr[])
    {
	int i;
	for (i = 0; i < arr.length - 1; i++)
	    if (arr[i] > arr[i + 1])
		return i;
	return arr.length - 1;
    }

    private static void reverse(long arr[], int a, int b)
    {
	long temp;
	for (int i = a; i <= b / 2; i++)
	{
	    temp = arr[i];
	    arr[i] = arr[b - i];
	    arr[b - i] = temp;
	}
    }

    private static boolean isSorted(long arr[])
    {
	for (int i = 0; i < arr.length - 1; i++)
	    if (arr[i] > arr[i + 1])
		return false;
	return true;
    }

    private static int last(long arr[])
    {
	int i;
	for (i = arr.length - 1; i > 0; i--)
	    if (arr[i] < arr[i - 1])
		return i;
	return 0;
    }

    public static void main(String args[])
    {
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	long arr[] = new long[n];

	for (int i = 0; i < n; i++)
	    arr[i] = sc.nextInt();

	int f = first(arr);
	int l = last(arr);

	if (f > l)
	    l = f = 0;
	else
	    reverse(arr, f, l);

	if (isSorted(arr))
	    System.out.println("yes\n" + (f + 1) + " " + (l + 1));
	else
	    System.out.println("no");

	sc.close();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main
{
    private static int first(long arr[])
    {
	int i;
	for (i = 0; i < arr.length - 1; i++)
	    if (arr[i] >= arr[i + 1])
		return i;
	return arr.length - 1;
    }

    private static boolean isSorted(long arr[])
    {
	for (int i = 0; i < arr.length - 1; i++)
	    if (arr[i] >= arr[i + 1])
		return false;
	return true;
    }

    private static int last(long arr[])
    {
	int i;
	for (i = arr.length - 1; i > 0; i--)
	    if (arr[i] <= arr[i - 1])
		return i;
	return 0;
    }

    public static void main(String args[])
    {
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	long arr[] = new long[n];

	for (int i = 0; i < n; i++)
	    arr[i] = sc.nextInt();

	int f = first(arr);
	int l = last(arr);

	if (f > l)
	    l = f = 0;
	else
	    Arrays.sort(arr, f, l + 1);

	if (isSorted(arr))
	    System.out.println("yes\n" + (f + 1) + " " + (l + 1));
	else
	    System.out.println("no");

	sc.close();
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main
{
    private static int first(long arr[])
    {
	int i;
	for (i = 0; i < arr.length - 1; i++)
	    if (arr[i] > arr[i + 1])
		return i;
	return arr.length - 1;
    }

    private static boolean isSorted(long arr[])
    {
	for (int i = 0; i < arr.length - 1; i++)
	    if (arr[i] > arr[i + 1])
		return false;
	return true;
    }

    private static int last(long arr[])
    {
	int i;
	for (i = arr.length - 1; i > 0; i--)
	    if (arr[i] < arr[i - 1])
		return i;
	return 0;
    }

    public static void main(String args[])
    {
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	long arr[] = new long[n];

	for (int i = 0; i < n; i++)
	    arr[i] = sc.nextInt();

	int f = first(arr);
	int l = last(arr);

	if (f > l)
	    l = f = 0;

	Arrays.sort(arr, f, l + 1);

	if (isSorted(arr))
	    System.out.println("yes\n" + (f + 1) + " " + (l + 1));
	else
	    System.out.println("no");

	sc.close();
    }
}


package com.company;

import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortArrays {
    public static void main(String [] ar){
        Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        int sg=0;
        int sgl=0;
        int st=a[0];
        boolean flag=true;
        try{
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){
                sgl=i;
                continue;
            }
            if(a[i]>a[i-1]){
                if(a[i]<st){
                    flag=false;
                    sgl=i-1;
                    break;
                }else{
                    if(i<n){
                        if(a[i+1]<a[i]){
                            sg=i;
                           // System.out.println(sg);}
                    }
                }
            }

        }}
        catch(ArrayIndexOutOfBoundsException e){}
        if(flag){
            System.out.println("yes");
            System.out.println(sg+1+" "+(sgl+1));
        }
        else
            System.out.println("no");
    }
}


import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortArrays {
    public static void main(String [] ar){
        Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        int sg=0;
        int sgl=0;
        int st=a[0];
        boolean flag=true;
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){
                sgl=i;
                continue;
            }
            if(a[i]>a[i-1]){
                if(a[i]<st){
                    flag=false;
                    sgl=i-1;
                    break;
                }
            }

        }
        if(flag){
            System.out.println("yes");
            System.out.println(sg+1+" "+(sgl+1));
        }
        else
            System.out.println("no");
    }
}


import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortArrays {
    public static void main(String [] ar){
        Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        int st=a[0];
        boolean flag=true;
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1])
                continue;
            if(a[i]>a[i-1]){
                if(a[i]<st){
                    flag=false;
                    st=a[i];
                }
            }
        }
        if(flag)
            System.out.println("yes");
        else
            System.out.println("no");
    }
}


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortTheArray2 {
    public static void main(String[] ar){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++)
            a[i]=s.nextInt();

        int []sort= Arrays.copyOf(a,n);
        Arrays.sort(sort);

        int start=n-1;
        int end=n-1;
        for(int i=0;i<n;i++){
            if(a[i]!=sort[i]){
                if(start==n-1)
                    start=i;
                end=i;
            }
        }
       // System.out.println(start+" "+end);
        for(int i=start;i<=end;i++){
            if(a[i]!=sort[end-(i-start)]){
                System.out.println("no");
                return;
            }
        }
        System.out.println("yes\n"+(start+1)+" "+(end+1));
    }
}


import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortArrays {
    public static void main(String [] ar){
        Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        int sg=0;
        int sgl=0;
        int st=a[0];
        boolean flag=true;
        try{
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){
                sgl=i;
                continue;
            }
            if(a[i]>a[i-1]){
                if(a[i]<st){
                    flag=false;
                    sgl=i-1;
                    break;
                }else{
                    if(i<n){
                        if(a[i+1]<a[i]){
                            sg=i;
                           // System.out.println(sg);}
                    }
                }
            }

        }}
        catch(ArrayIndexOutOfBoundsException e){}
        if(flag){
            System.out.println("yes");
            System.out.println(sg+1+" "+(sgl+1));
        }
        else
            System.out.println("no");
    }
}


import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortArrays {
    public static void main(String [] ar){
        Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        int sg=0;
        int sgl=0;
        int st=a[0];
        boolean flag=true;
        try{
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){
                sgl=i;
                continue;
            }
            if(a[i]>a[i-1]){
                if(a[i]<st){
                    flag=false;
                    sgl=i-1;
                    break;
                }else{
                    if(i<n){
                        if(a[i+1]<a[i]){
                            sg=i;
                           // System.out.println(sg);
                        }
                    }
                }
            }

        }
        }
        catch(ArrayIndexOutOfBoundsException e){}
        if(flag){
            System.out.println("yes");
            System.out.println(sg+1+" "+(sgl+1));
        }
        else
            System.out.println("no");
    }
}


package com.company;

import java.util.Scanner;

/**
 * Created by Hp on 3/29/2016.
 */
public class SortArrays {
    public static void main(String [] ar){
        Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int []a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=s.nextInt();
        }
        int sg=0;
        int sgl=0;
        int st=a[0];
        boolean flag=true;
        for(int i=1;i<n;i++){
            if(a[i]<=a[i-1]){
                sgl=i;
                continue;
            }
            if(a[i]>a[i-1]){
                if(a[i]<st){
                    flag=false;
                    sgl=i-1;
                    break;
                }
            }

        }
        if(flag){
            System.out.println("yes");
            System.out.println(sg+1+" "+(sgl+1));
        }
        else
            System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s2<n&&a[s1-1]<a[s2])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s2==n)
        c=0;
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s1==1&&s2==n)
        c=0;
        else if(s1==1&&a[s1-1]<a[s2])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s2==n&&a[s2-1]>a[s1-2])
        c=0;
        else if(a[s1-1]<a[s2]&&a[s2-1]>a[s1-2])
        {
             while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s2<n&&a[s1-1]<a[s2]&&a[s1-2]<a[s2-1])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s2==n&&a[s1-2]<a[s2-1])
        c=0;
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s1==1&&s2==n)
        c=0;
        else if(s1==1&&a[s1-1]<a[s2])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s2==n&&a[s2-1]>a[s1-2])
        c=0;
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s2<n&&a[s1-1]<a[s2]&&a[s1-2]<a[s2-1])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s1>2&&s2==n&&a[s1-2]<a[s2-1])
        c=0;
        else if(s2==0)
        c=0;
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s1==1&&s2==n)
        c=0;
        else if(s1==1&&a[s1-1]<a[s2])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s2==n)
        {
            if(a[s2-1]>a[s1-2])
            c=0;
            else
            c=1;
        }
        else if(a[s1-1]<a[s2]&&a[s2-1]>a[s1-2])
        {
             while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}


import java.util.*;
public class file
{
    public static void main(String args[])
    {
        Scanner in =new Scanner(System.in);
        int n=in.nextInt();
        int a[]=new int[n];
        for(int i=0; i<n; i++)
        a[i]=in.nextInt();
        int i=0; int s1=1; int s2=1; int c=0;
        while(i<n-1&&a[i]<a[i+1])
        i++;
        s1=i+1;
        while(i<n-1&&a[i]>a[i+1])
        i++;
        s2=i+1;
        if(s2<n&&a[s1-1]<a[s2]&&a[s1-2]<a[s2-1])
        {
            while(i<n-1)
            {
                if(a[i]>a[i+1])
                {
                    c=1;
                    break;
                }
                i++;
            }
        }
        else if(s1>2&&s2==n&&a[s1-2]<a[s2-1])
        c=0;
        else if(s2==n||s1==1)
        c=0;
        else
        c=1;
        if(c==0)
        {
            System.out.println("yes");
            System.out.println(s1+" "+s2);
        }
        else
        System.out.println("no");
    }
}