#define _CRT_SECURE_NO_WARNINGS #define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING #include using namespace std; const int N = 10010, M = 100010; int adj[N], nxt[M << 1], to[M << 1], ecnt, col[N]; inline void addEdge(int f, int t) { ecnt++; nxt[ecnt] = adj[f]; adj[f] = ecnt; to[ecnt] = t; } void dfs(int x) { for (int e = adj[x], t; e; e = nxt[e]) if (t = to[e], !col[to[e]]) { col[t] = 3 - col[x]; dfs(t); } } int main() { int T; scanf("%d", &T); while (T--) { memset(adj, 0, sizeof(adj)), ecnt = 0; memset(col, 0, sizeof(col)); int n, m, u, v; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) scanf("%d%d", &u, &v), addEdge(u, v), addEdge(v, u); if (m == 0) u = 1; col[u] = 1; dfs(u); int cnt[] = {0, 0, 0}; for (int i = 1; i <= n; i++) cnt[col[i]]++; int ans = 0; for (int i = 0; i <= cnt[0]; i++) ans = max(ans, (cnt[1] + i) * (cnt[2] + cnt[0] - i)); printf("%d\n", ans - m); } return 0; }