#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int add(int a, int b) { return (a + b) % mod; }
int mul(long long a, long long b) { return a * b % mod; }
int qpow(int b, int a = 2) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = mul(ret, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ret;
}
const int maxm = 4e5 + 10;
vector<int> mat[maxm];
int flag[maxm];
pair<int, int> dfs(int a, int flag_ = 1) {
  flag[a] = flag_;
  pair<int, int> ret = make_pair(0, 0);
  if (flag_ == 1)
    ret.first++;
  else
    ret.second++;
  for (int i : mat[a]) {
    if (flag[i] && flag[i] == flag_) {
      return make_pair(-1, -1);
    }
    if (flag[i]) continue;
    pair<int, int> now = dfs(i, 3 ^ flag_);
    if (now.first == -1) return now;
    ret.first += now.first;
    ret.second += now.second;
  }
  return ret;
}
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (m == 0) {
    printf("%d\n", qpow(n, 3));
    return;
  }
  for (int i = 1; i <= n; i++) mat[i].clear(), flag[i] = 0;
  for (int i = 1, from, to; i <= m; i++) {
    scanf("%d%d", &from, &to);
    mat[from].push_back(to);
    mat[to].push_back(from);
  }
  int cnt3 = 0;
  int ans = 1;
  for (int i = 1; i <= n; i++) {
    if (mat[i].size() == 0)
      cnt3++;
    else {
      if (flag[i]) continue;
      pair<int, int> ret = dfs(i);
      if (ret.first == -1) {
        puts("\t0");
        return;
      }
      ans = mul(ans, add(qpow(ret.first), qpow(ret.second)));
    }
  }
  ans = mul(ans, qpow(cnt3, 3));
  printf("%d\n", ans);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
