#include <bits/stdc++.h>
using namespace std;
long long M = 998244353;
long long t, n, m, cnt0, cnt1, ans;
vector<vector<long long> > g;
vector<long long> used;
vector<long long> p;
bool f;
void dfs(long long v) {
  used[v] = 1;
  if (p[v])
    cnt1++;
  else
    cnt0++;
  for (long long u : g[v]) {
    if (!used[u]) {
      p[u] = (p[v] + 1) % 2;
      dfs(u);
    } else if (p[u] == p[v]) {
      f = 0;
    }
  }
}
long long binpow(long long a, long long p) {
  if (p == 0) return 1;
  if (p % 2 == 1) return (binpow(a, p - 1) * a) % M;
  long long tmp = binpow(a, p / 2);
  return (tmp * tmp) % M;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    g.resize(n);
    used.resize(n);
    p.resize(n);
    cnt0 = cnt1 = 0;
    f = 1;
    ans = 1;
    for (long long i = 0; i < m; i++) {
      long long v, u;
      cin >> v >> u;
      v--;
      u--;
      g[v].push_back(u);
      g[u].push_back(v);
    }
    for (long long i = 0; i < n; i++) {
      if (!used[i]) {
        cnt0 = cnt1 = 0;
        dfs(i);
        if (cnt0 + cnt1 == 0) {
          ans = (ans * 3) % M;
        } else {
          ans = (ans * ((binpow(2, cnt1) + binpow(2, cnt0)) % M)) % M;
        }
      }
    }
    if (!f) {
      cout << 0 << endl;
    } else {
      cout << ans << endl;
    }
    g.clear();
    used.clear();
    p.clear();
  }
  return 0;
}
