#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int info[2 * N];
  fill(info, info + 2 * N, -1);
  int A[N], B[N];
  bool ng = false;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    if (A[i] != -1) {
      if (info[--A[i]] != -1) ng = true;
      info[A[i]] = i;
    }
    if (B[i] != -1) {
      if (info[--B[i]] != -1) ng = true;
      info[B[i]] = i + N;
    }
  }
  if (ng) {
    cout << "No" << '\n';
    return 0;
  }
  auto check = [&](int l, int r) {
    int k = r - l + 1;
    for (int i = l; i - l < k / 2; i++) {
      if (info[i] != -1 && info[i] >= N) return false;
      if (info[i + k / 2] != -1 && info[i + k / 2] < N) return false;
      if (info[i] != -1 && info[i + k / 2] != -1
          && info[i] != info[i + k / 2] - N)
        return false;
      if (info[i] != -1 && B[info[i]] != -1 && B[info[i]] != i + k / 2)
        return false;
      if (info[i + k / 2] != -1 && A[info[i + k / 2] - N] != -1
          && A[info[i + k / 2] - N] != i)
        return false;
    }
    return true;
  };
  bool dp[2 * N][2 * N];
  for (int k = 2; k <= 2 * N; k += 2) {
    for (int l = 0; l + k - 1 < 2 * N; l += 2) {
      int r = l + k - 1;
      dp[l][r] = check(l, r);
      for (int j = l + 1; j + 1 < r; j += 2)
        dp[l][r] |= dp[l][j] & dp[j + 1][r];
    }
  }
  cout << (dp[0][2 * N - 1] ? "Yes" : "No") << '\n';
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
template<typename T>
void read(T&x){
    x=0;
    char ch=getchar();
    int f=1;
    while(!isdigit(ch)){
        if(ch=='-')f*=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        x=x*10+(ch-'0');
        ch=getchar();
    }x*=f;
}
//========================================================
typedef long long ll;
ll t,l,r;

int main(){
    read(t);
    while(t--){
        read(l),read(r);
        printf("%lld\n",r>=2*l?(r-l+1)*(r-2*l+1)-r*(r-2*l+1)/2:0ll);
    }
    return 0;
}