#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;
long long int c1 = 0;
long long int c2 = 0;
vector<long long int> adj[400000];
long long int vis[400000];
void dfs(long long int r, long long int c) {
  c1++;
  if (c == 0) {
    c2++;
  }
  vis[r] = c;
  for (long long int i = 0; i < adj[r].size(); i++) {
    if (vis[adj[r][i]] == -1) {
      dfs(adj[r][i], 1 - c);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    for (long long int i = 0; i < n; i++) {
      adj[i].clear();
      vis[i] = -1;
    }
    for (long long int i = 0; i < m; i++) {
      long long int j, k;
      cin >> j >> k;
      adj[j - 1].push_back(k - 1);
      adj[k - 1].push_back(j - 1);
    }
    long long int count = 0;
    long long int ans = 1;
    for (long long int i = 0; i < n; i++) {
      if (adj[i].size() == 0) {
        count++;
        continue;
      }
      if (vis[i] == -1) {
        c1 = 0;
        c2 = 0;
        dfs(i, 0);
        long long int temp = 1;
        long long int temp1 = 1;
        for (long long int i = 0; i < c2; i++) {
          temp = (temp * 2) % MOD;
        }
        for (long long int i = 0; i < c1 - c2; i++) {
          temp1 = (temp1 * 2) % MOD;
        }
        temp = (temp + temp1) % MOD;
        ans = (ans * temp) % MOD;
      }
    }
    long long int f = 0;
    long long int cst = 3;
    for (long long int i = 0; i < n; i++) {
      if (adj[i].size() > 0) {
        f = 0;
        for (long long int j = 0; j < adj[i].size(); j++) {
          if (vis[i] == vis[adj[i][j]]) {
            f = 1;
            break;
          }
        }
        if (f) {
          break;
        }
      }
    }
    for (long long int i = 0; i < count; i++) {
      ans = (ans * cst) % MOD;
    }
    if (f) {
      cout << "0\n";
    } else {
      cout << ans << "\n";
    }
  }
  return 0;
}
