#include <bits/stdc++.h>
using namespace std;
long long p[500005], q[500005];
long long to[505] = {0}, now[505] = {0};
long long n, ans;
void calc() {
  long long ret = 0, i, j;
  for (i = 1; i <= n; i++) {
    if (now[i] < i) continue;
    for (j = i + 1; j <= n; j++) {
      if (now[j] < j) continue;
      if (i < j && j < now[i] && now[i] < now[j]) ret++;
    }
  }
  ans = max(ans, ret);
  return;
}
void solve(long long p1, long long p2, long long all) {
  if (all == n / 2) {
    calc();
    return;
  }
  if (p1 > n) p1 -= n;
  if (p2 > n) p2 -= n;
  if (now[p2] || p1 == p2)
    solve(p1, p2 + 1, all);
  else if (now[p1])
    solve(p1 + 1, p2, all);
  else {
    now[p1] = p2;
    now[p2] = p1;
    solve(p1 + 1, p2 + 1, all + 1);
  }
  return;
}
int main() {
  long long t, m, i, j, k, t1, t2;
  cin >> t;
  while (t--) {
    scanf("%lld %lld", &n, &k);
    n *= 2;
    for (i = 1; i <= n; i++) {
      to[i] = 0;
      now[i] = 0;
    }
    for (i = 1; i <= k; i++) {
      scanf("%lld %lld", &t1, &t2);
      to[t1] = t2;
      to[t2] = t1;
    }
    ans = 0;
    long long uncalced = 1;
    for (i = 1; i <= n; i++) {
      if (uncalced) {
        for (long long temp = 1; temp <= n; temp++) {
          now[temp] = to[temp];
        }
        calc();
        uncalced = 0;
      }
      if (to[i])
        continue;
      else {
        for (j = i + 1; j <= i + n; j++) {
          for (long long temp = 1; temp <= n; temp++) {
            now[temp] = to[temp];
          }
          solve(i, j, k);
        }
        break;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
