#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long modpow(long long a, long long e) {
  if (e == 0) return 1;
  long long x = modpow(a * a % mod, e >> 1);
  return e & 1 ? x * a % mod : x;
}
long long colorComp(long long source, vector<vector<int>>& adj,
                    vector<int>& color, int n) {
  queue<int> q;
  q.push(source);
  color[source] = 1;
  int ones = 1, zeros = 0;
  bool failed = false;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < adj[u].size(); i++) {
      int v = adj[u][i];
      if (color[v] == -1) {
        color[v] = 1 ^ color[u];
        if (color[v] == 1)
          ones++;
        else
          zeros++;
        q.push(v);
      } else if (color[v] == color[u]) {
        return -1;
      }
    }
  }
  if (zeros + ones == 1) {
    return 3;
  }
  return modpow(2, ones) + modpow(2, zeros);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    vector<vector<int>> adj;
    vector<int> color;
    int n, m;
    cin >> n >> m;
    adj.resize(n);
    color.assign(n, -1);
    for (int i = 0; i < m; ++i) {
      int x, y;
      cin >> x >> y;
      adj[--y].push_back(--x);
      adj[x].push_back(y);
    }
    bool failed = false;
    long long ans = 1;
    for (int i = 0; i < n; i++) {
      if (color[i] != -1) continue;
      long long ret = colorComp(i, adj, color, n);
      if (ret == -1) {
        failed = true;
        goto next;
      } else
        ans = (ans * ret) % mod;
    }
  next:
    if (!failed) {
      cout << ans << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
