#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
map<int, int> l;
map<int, int> mp;
map<int, int> visited;
vector<int> adj[N];
long long power(long long a, long long b) {
  long long ret = 1;
  for (long long i = 0; i < b; i++) ret = (ret * a) % 998244353;
  return ret;
}
int cur = 1;
void DFS(int s, int p, int c) {
  if (visited[s]) {
    if (l[s] != c) cur = 0;
    return;
  }
  visited[s] = 1;
  l[s] = c, mp[c]++;
  for (auto x : adj[s])
    if (x != p) DFS(x, s, !c);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    long long res = 1;
    if (n == 1) {
      cout << 3 << endl;
      continue;
    }
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    for (int i = 1; i <= n; i++) {
      if (!visited[i]) {
        cur = 1;
        mp.clear();
        DFS(i, -1, 0);
        res =
            1LL * cur *
            (res * (power(2, mp[0]) % 998244353 + power(2, mp[1]) % 998244353) %
             998244353) %
            998244353;
      }
    }
    cout << res << endl;
    mp.clear();
    l.clear();
    visited.clear();
    for (int i = 1; i <= n; i++) adj[i].clear();
  }
  return 0;
}
