#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long n, m, u, v, ans, emp = 1, tmp = 1, SZ, cnt, col[N], ANS[N],
                           comp_ans[N], compn, mod = 998244353;
vector<int> adj[N];
bool vis[N], check;
void DFS(int x) {
  SZ++;
  vis[x] = 1;
  for (auto X : adj[x]) {
    if (!col[X]) {
      if (col[x] == 2) {
        col[X] = 1;
        cnt++;
      } else {
        col[X] = 2;
      }
    }
    if ((col[x] + col[X]) % 2 == 0) {
      check = 1;
    }
  }
  for (auto X : adj[x]) {
    if (!vis[X]) {
      DFS(X);
    }
  }
}
void init() {
  compn = 0;
  check = 0;
  ans = 1;
  emp = 1;
  tmp = 1;
  for (int i = 0; i <= n; i++) {
    vis[i] = 0;
    col[i] = 0;
    adj[i].clear();
  }
}
int main() {
  ANS[0] = 1;
  for (int i = 1; i < N; i++) {
    ANS[i] = 2 * ANS[i - 1];
    ANS[i] %= mod;
    ANS[i] %= mod;
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    init();
    scanf("%lld%lld", &n, &m);
    for (int i = 0; i < m; i++) {
      scanf("%lld%lld", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) {
        SZ = 0;
        cnt = 0;
        col[i] = 2;
        DFS(i);
        if (check) {
          printf("0\n");
          break;
        }
        if (SZ == 1) {
          comp_ans[compn++] = 3;
          continue;
        }
        comp_ans[compn] = ANS[cnt];
        comp_ans[compn++] += ANS[SZ - cnt];
      }
    }
    if (check) continue;
    ans = comp_ans[0];
    ans %= mod;
    ans %= mod;
    for (int i = 1; i < compn; i++) {
      ans *= comp_ans[i];
      ans %= mod;
      ans %= mod;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
