#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const long long N = 210;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
long long n, K, vis[N], g[N];
struct Node {
  long long l, r;
} a[N];
inline bool Check(long long x, long long y) {
  Node p = a[x], q = a[y];
  if (p.l > q.l) swap(p, q);
  return (q.l < p.r && p.r < q.r);
}
signed main() {
  for (register long long T = read(); T; T--) {
    memset(vis, 0, sizeof(vis));
    n = read(), K = read();
    for (register long long i = 1; i <= K; i++) {
      a[i].l = read(), a[i].r = read();
      if (a[i].l > a[i].r) swap(a[i].l, a[i].r);
      vis[a[i].l] = vis[a[i].r] = 1;
    }
    long long m = 0;
    for (register long long i = 1; i <= n * 2; i++) {
      if (!vis[i]) g[++m] = i;
    }
    long long sz = n - K;
    for (register long long i = 1; i <= sz; i++) {
      a[++K] = (Node){g[i], g[i + sz]};
    }
    long long ans = 0;
    for (register long long i = 1; i <= n; i++) {
      for (register long long j = i + 1; j <= n; j++) {
        if (Check(i, j)) ans++;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
