#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int T, n, m, ans, cnt, a[N], b[N], vis[N], p[N];
inline int check(int x, int y) {
  int id = a[x], fl1 = 0, fl2 = 0;
  while (id != b[x]) {
    ++id;
    if (id > 2 * n) id -= 2 * n;
    if (id == a[y]) fl1 = 1;
    if (id == b[y]) fl2 = 1;
  }
  if (fl1 && fl2) return 0;
  if ((!fl1) && (!fl2)) return 0;
  return 1;
}
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> m, ans = 0, cnt = 0;
    for (int i = 1; i <= 2 * n; ++i) vis[i] = 0;
    for (int i = 1; i <= m; ++i) cin >> a[i] >> b[i], vis[a[i]] = vis[b[i]] = 1;
    for (int i = 1; i <= 2 * n; ++i)
      if (!vis[i]) p[++cnt] = i;
    sort(p + 1, p + 1 + cnt);
    for (int i = 1; i <= cnt / 2; ++i) a[++m] = p[i], b[m] = p[i + cnt / 2];
    for (int i = 1; i <= n; ++i)
      for (int j = i + 1; j <= n; ++j) ans += check(i, j);
    printf("%d\n", ans);
  }
  return 0;
}
