#include <bits/stdc++.h>
using namespace std;
long long int n, m, t, c[300007], r = 0, cnt = 0, l, k, e;
long long int two[300007], ans;
vector<int> v[300007];
int dfs(int a) {
  c[a] = (r + 1) % 2;
  if (c[a] == 1) {
    k++;
  }
  cnt++;
  for (int i = 0; i < v[a].size(); i++) {
    int to = v[a][i];
    if (c[to] == c[a]) {
      i = v[a].size();
      e = 1;
    }
    if (c[to] == -1 && e == 0) {
      r = c[a];
      dfs(to);
    }
  }
  if (e == 1) {
    return -1;
  } else {
    return cnt;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  two[0] = 1;
  c[0] = -1;
  for (int i = 1; i <= 300000; i++) {
    two[i] = (two[i - 1] * 2) % 998244353;
    c[i] = -1;
  }
  for (int j = 0; j < t; j++) {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    ans = 1;
    for (int i = 0; i < n; i++) {
      cnt = 0;
      k = 0;
      e = 0;
      if (c[i] == -1) {
        l = dfs(i);
        if (l == -1) {
          cout << 0 << "\n";
          i = n;
        } else {
          if (l != 1) {
            ans = (ans * (two[l - k] + two[k])) % 998244353;
          } else {
            ans = ans * 3 % 998244353;
          }
        }
      }
      if (i == n - 1) {
        cout << ans << "\n";
      }
    }
    for (int i = 0; i < n; i++) {
      c[i] = -1;
      v[i].clear();
    }
  }
  return 0;
}
