#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000010;
const int Mod = 998244353;
int Laxt[maxn], Next[maxn], To[maxn], cnt, num1, num2, vis[maxn], tot, ans;
void add(int u, int v) {
  Next[++cnt] = Laxt[u];
  Laxt[u] = cnt;
  To[cnt] = v;
}
void dfs(int u, int f, int x, int y) {
  tot++;
  vis[u] = 1;
  if (x == 1) num1 = num1 * 2 % Mod;
  if (y == 1) num2 = num2 * 2 % Mod;
  for (int i = Laxt[u]; i; i = Next[i]) {
    if (To[i] != f && !vis[To[i]]) dfs(To[i], u, 1 - x, 1 - y);
  }
}
int fa[maxn];
int find(int x) {
  if (fa[x] == x) return x;
  return fa[x] = find(fa[x]);
}
int main() {
  int T, N, M, u, v;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= N; i++) Laxt[i] = 0;
    cnt = 0;
    for (int i = 1; i <= N + N; i++) fa[i] = i, vis[i] = 0;
    bool F = true;
    for (int i = 1; i <= M; i++) {
      scanf("%d%d", &u, &v);
      add(u, v);
      add(v, u);
      if (find(u) == find(v)) F = false;
      fa[find(u)] = find(v + N);
      fa[find(v)] = find(u + N);
    }
    if (!F)
      puts("0");
    else {
      ans = 1;
      for (int i = 1; i <= N; i++) {
        if (!vis[i]) {
          num1 = 1;
          num2 = 1;
          tot = 0;
          dfs(i, 0, 0, 1);
          if (tot == 1)
            ans = 3LL * ans % Mod;
          else
            ans = 1LL * ans * (num1 + num2) % Mod;
        }
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}
