#include <bits/stdc++.h>
using namespace std;
bool checkBit(long long int n, long long int i) { return (n & (1LL << i)); }
long long int setBit(long long int n, long long int i) {
  return (n | (1LL << i));
}
long long int resetBit(long long int n, long long int i) {
  return (n & (~(1LL << i)));
}
const long long int MX = 1e18;
const long long int mod = 998244353;
vector<int> v[300003];
int vis[300003], vis_2[300003], flag, val[300003];
long long int ans = 0, temp = 0;
void dfs_1(int u, int col, int par) {
  if (vis[u] == 1) return;
  vis[u] = 1;
  for (auto x : v[u]) {
    if (x == par) continue;
    if (vis[x] == 1 and val[x] == val[u] and val[x] != -1) {
      flag = 1;
      return;
    }
    if (vis[x] == 1) continue;
    if (col == 0) {
      temp *= 2;
      val[x] = 1;
      if (temp >= mod) temp %= mod;
    } else
      val[x] = 0;
    dfs_1(x, col ^ 1, u);
  }
}
void dfs_2(int u) {
  if (vis_2[u]) return;
  val[u] = -1;
  vis_2[u] = 1;
  vis[u] = 0;
  for (auto x : v[u]) {
    if (vis_2[x] == 1) continue;
    dfs_2(x);
  }
}
void clear(int n) {
  ans = 0, temp = 0;
  for (int i = 1; i <= n; i++) {
    v[i].clear();
    vis[i] = 0;
    vis_2[i] = 0;
    val[i] = -1;
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long int ans = 1;
  for (int i = 1; i <= n; i++) {
    val[i] = -1;
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i] and (int) v[i].size() > 0) {
      long long int temp1 = 0;
      flag = 0;
      temp = 2;
      val[i] = 1;
      dfs_1(i, 1, 0);
      if (flag == 0) {
        temp1 += temp;
        if (temp1 >= mod) temp1 %= mod;
      }
      dfs_2(i);
      temp = 1;
      flag = 0;
      val[i] = 0;
      dfs_1(i, 0, 0);
      if (flag == 0) {
        temp1 += temp;
        if (temp1 >= mod) temp1 %= mod;
      }
      ans *= temp1;
      if (ans >= mod) {
        ans %= mod;
      }
    } else if ((int)v[i].size() == 0) {
      ans *= 3;
      if (ans >= mod) ans %= mod;
    }
  }
  if (ans == 1) ans = 0;
  cout << ans << "\n";
  clear(n);
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
}
