#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
vector<long long int> marked(1000005, 0);
vector<long long int> color(1000005, -1);
vector<list<long long int> > G;
long long int ev = 0, od = 0;
long long int ans = 0;
void input(long long int v) {
  vector<list<long long int> > G1(v);
  G = G1;
  long long int e, at, to;
  cin >> e;
  while (e--) {
    cin >> at >> to;
    G[at - 1].push_back(to - 1);
    G[to - 1].push_back(at - 1);
  }
  return;
}
void DFS(long long int i, long long int col) {
  if (ans == 1) return;
  if (marked[i]) return;
  marked[i] = -1;
  color[i] = col;
  if (col == 0)
    ev++;
  else
    od++;
  for (auto j : G[i]) {
    if (marked[j] == -1) {
      if (color[j] != 1 - col) ans = 1;
    } else
      DFS(j, 1 - col);
  }
  return;
}
long long int fexpo(long long int a, long long int b) {
  if (a == 1) return 1;
  if (b == 0) return 1;
  if (b == 1) return a % 998244353;
  long long int ans = fexpo(a, b / 2) % 998244353;
  if (b % 2 == 0)
    return (ans * ans) % 998244353;
  else
    return (((a * ans) % 998244353) * ans) % 998244353;
}
void foo(long long int v) {
  for (long long int i = 0; i <= v; i++) {
    marked[i] = 0;
    color[i] = -1;
  }
  ans = 0;
  G.clear();
  od = 0;
  ev = 0;
  return;
}
void solve() {
  long long int v = 0, e = 0, i = 0, a = 0, b = 0, c = 0, d = 0, k = 0, t = 0,
                m = -20000000000000000, n = 0, q = 0, j = 0;
  cin >> v;
  foo(v);
  input(v);
  long long int pdt = 1;
  for (i = 0; i < v; i++) {
    ev = od = 0;
    t = 0;
    if (marked[i] == 0) {
      DFS(i, 0);
      if (ans == 1) break;
      t += fexpo(2, ev) + fexpo(2, od);
      t %= 998244353;
      pdt *= t;
      pdt %= 998244353;
    }
  }
  if (ans == 1) pdt = 0;
  cout << pdt << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  cout << endl;
  return 0;
}
