#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 300005;
vector<int> v[N];
vector<int> visited(N, 0);
vector<int> tmp;
void muls(int& a, int b) {
  a = 1LL * a * b % mod;
  return;
}
void dfs(int u) {
  assert(visited[u] == 0);
  visited[u] = 1;
  tmp.push_back(u);
  for (auto ch : v[u]) {
    if (visited[ch] == 1) continue;
    dfs(ch);
  }
  return;
}
int calc(int u) {
  int ans[3];
  for (int col : {1, 2}) {
    for (auto k : tmp) {
      visited[k] = 0;
    }
    ans[col] = 1;
    queue<int> q;
    q.push(u);
    visited[u] = col;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      if (visited[u] == 1) muls(ans[col], 2);
      for (auto ch : v[u]) {
        if (visited[ch] == 0) {
          visited[ch] = 1 - visited[u] + 2;
          q.push(ch);
        } else {
          if (visited[ch] == visited[u]) {
            ans[col] = 0;
          }
        }
      }
    }
  }
  for (auto k : tmp) {
    visited[k] = 1;
  }
  return (ans[1] + ans[2]) % mod;
}
void test_case() {
  int n, i, p, q, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (i = 0; i < n; i++) {
    v[i].clear();
    visited[i] = 0;
  }
  for (i = 0; i < m; i++) {
    scanf("%d", &p);
    scanf("%d", &q);
    p--;
    q--;
    v[p].push_back(q);
    v[q].push_back(p);
  }
  int ans = 1;
  for (i = 0; i < n; i++) {
    if (visited[i] == 1) continue;
    tmp.clear();
    dfs(i);
    if (tmp.size() == 1) {
      muls(ans, 3);
      continue;
    }
    muls(ans, calc(i));
  }
  printf("%d\n", ans);
  return;
}
signed main() {
  int t;
  t = 1;
  scanf("%d", &t);
  while (t--) {
    test_case();
  }
}
