#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 4, MOD = 998244353;
vector<int> adj[N];
int cnt[2], c[N];
bool bad = false;
void check_bipartite(int node, bool col) {
  c[node] = col;
  cnt[col]++;
  for (int child : adj[node]) {
    if (~c[child] && col == c[child]) bad = true;
    if (c[child] == -1) check_bipartite(child, col ^ 1);
  }
}
int add(int a, int b) {
  a %= MOD;
  b %= MOD;
  return (1ll * a + b) % MOD;
}
int mul(int a, int b) {
  a %= MOD;
  b %= MOD;
  return (1ll * a * b) % MOD;
}
int mod(int x, int n, int m) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0) {
    int y = mod(x, n / 2, m);
    return (1ll * y * y) % m;
  } else {
    return (1ll * (x % m) * mod(x, n - 1, m)) % m;
  }
}
int n, m;
void init() {
  bad = false;
  cnt[0] = cnt[1] = 0;
  for (int i = 0; i < n; ++i) adj[i].clear(), c[i] = -1;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    init();
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    int ans = 1, lst0 = 0, lst1 = 0;
    for (int i = 0; i < n; ++i) {
      if (c[i] == -1) {
        check_bipartite(i, 0);
        if (cnt[1] - lst1 + cnt[0] - lst0 == 1)
          ans = mul(ans, 3);
        else
          ans = mul(
              ans, add(mod(2, cnt[1] - lst1, MOD), mod(2, cnt[0] - lst0, MOD)));
        lst0 = cnt[0], lst1 = cnt[1];
      }
    }
    cout << (bad ? 0 : ans) << '\n';
  }
}
