#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const int mod = 998244353;
long long t, n, m;
vector<long long> G[maxn];
set<long long> s;
long long _0 = 0, _1 = 0, _2 = 0;
bool v[maxn], k[maxn];
vector<pair<long long, long long> > a;
void dfs(long long now) {
  for (long long i : G[now]) {
    if (!v[i]) {
      v[i] = 1;
      k[i] = (!k[now]);
      if (k[i])
        _1++;
      else
        _0++;
      dfs(i);
    }
  }
}
long long ppow(long long a, long long b) {
  if (b == 0)
    return 1;
  else if (b == 1)
    return a;
  else if (b & 1) {
    long long now = ppow(a, b / 2);
    return now * now % mod * a % mod;
  } else {
    long long now = ppow(a, b / 2);
    return now * now % mod;
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    for (long long i : s) G[i].clear();
    _0 = 0, _1 = 0, _2 = 0;
    s.clear();
    for (long long i = 1; i <= n; i++) v[i] = 0, k[i] = 0;
    a.clear();
    cin >> n >> m;
    for (long long i = 1; i <= m; i++) {
      long long x, y;
      cin >> x >> y;
      s.insert(x);
      s.insert(y);
      G[x].push_back(y);
      G[y].push_back(x);
      a.push_back(make_pair(x, y));
    }
    long long ans = 1;
    for (long long i = 1; i <= n; i++) {
      if (!v[i]) {
        v[i] = 1;
        if (G[i].size() == 0)
          ans = (ans * 3) % mod;
        else {
          _0 = 0, _1 = 0;
          v[i] = 1, dfs(i), _0++;
          ans = (ans * ((ppow(2, _0) % mod + ppow(2, _1) % mod) % mod)) % mod;
        }
      }
    }
    bool ok = 1;
    for (pair<long long, long long> i : a) {
      if (k[i.first] == k[i.second]) ok = 0;
    }
    if (!ok)
      cout << 0 << endl;
    else
      cout << ans << endl;
  }
}
