#include <bits/stdc++.h>
using namespace std;
long long int llmax(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
long long int llmin(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
long long int mod = 998244353;
vector<int> a[300005];
vector<bool> vis(300005, false);
vector<int> col(300005, 0);
vector<long long int> pe, qe;
long long int p, q;
vector<int> checker;
long long int multi(long long int x, long long int y) {
  x %= mod;
  if (y == 0) return 1;
  if (y == 1) return x;
  if (y % 2)
    return (x * (multi((x * x) % mod, y / 2) % mod)) % mod;
  else
    return multi((x * x) % mod, y / 2) % mod;
}
void dfs(int i, int co) {
  if (vis[i]) return;
  vis[i] = true;
  col[i] = co;
  checker.push_back(i);
  if (co)
    p++;
  else
    q++;
  for (int j = 0; j < a[i].size(); j++) {
    if (vis[a[i][j]] == false) {
      dfs(a[i][j], (co + 1) % 2);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    for (int i = 1; i < n + 1; i++) {
      a[i].clear();
      vis[i] = false;
      col[i] = 0;
      pe.clear();
      qe.clear();
    }
    int x, y;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      a[x].push_back(y);
      a[y].push_back(x);
    }
    int f, fo = 1;
    vector<int> jacuzi;
    for (int i = 1; i < n + 1; i++) {
      p = q = 0;
      checker.clear();
      f = 0;
      if (vis[i] == false) {
        dfs(i, 0);
        for (int k = 0; k < checker.size(); k++) {
          for (int j = 0; j < a[checker[k]].size(); j++) {
            if (col[checker[k]] == col[a[checker[k]][j]]) {
              f = 1;
              break;
            }
          }
          if (f) break;
        }
        jacuzi.push_back(f);
        if (f) fo = 0;
        pe.push_back(p);
        qe.push_back(q);
      }
    }
    if (fo == 0) {
      cout << 0 << endl;
    } else {
      vector<long long int> fans;
      for (int i = 0; i < pe.size(); i++) {
        if (jacuzi[i] == 0) {
          long long int ans = 0;
          if (pe[i] == 0 || qe[i] == 0) {
            fans.push_back(3);
          } else {
            if (qe[i] > 0) ans = (ans + (multi(2, qe[i]) % mod)) % mod;
            if (pe[i] > 0) ans = (ans + (multi(2, pe[i]) % mod)) % mod;
            fans.push_back(ans);
          }
        }
      }
      long long int tans = 1;
      for (int i = 0; i < fans.size(); i++) {
        tans = (tans * fans[i]) % mod;
      }
      cout << tans << endl;
    }
  }
}
