#include <bits/stdc++.h>
using namespace std;
const long double ep = 0.000001;
const long double PI = 3.14159265359;
const int mod = 998244353;
const int MAX = 300009;
long long n, m, l[4], x, y, t, vis[MAX], po[2 * MAX], color[MAX], visited[MAX],
    po3[2 * MAX];
vector<long long> d[MAX];
bool check(long long v) {
  if (!visited[v]) {
    visited[v] = 1;
    for (auto u : d[v]) {
      if (visited[u] == false) {
        color[u] = 1 - color[v];
        if (!check(u)) return false;
      } else if (color[u] == color[v])
        return false;
    }
  }
  return true;
}
long long bfs(long long s) {
  if (vis[s]) return 0;
  queue<pair<long long, bool>> q;
  q.push({s, 0});
  vis[s] = 1;
  while (!q.empty()) {
    pair<long long, bool> vll = q.front();
    long long v = vll.first;
    bool le = vll.second;
    q.pop();
    l[le]++;
    for (auto u : d[v]) {
      if (!vis[u]) {
        vis[u] = 1;
        q.push({u, 1 - le});
      }
    }
  }
  if (d[s].size() == 0)
    return 3;
  else
    return 0;
}
int main() {
  po[0] = 1;
  po3[0] = 1;
  for (int i = 1; i <= 2 * MAX - 5; i++)
    po[i] = ((po[i - 1] * 2) % mod + mod) % mod;
  for (int i = 1; i <= 2 * MAX - 5; i++)
    po3[i] = ((po3[i - 1] * 3) % mod + mod) % mod;
  cin >> t;
  while (t--) {
    long long ans = 1;
    bool c = 1;
    cin >> n >> m;
    if (m == 0) {
      cout << po3[n];
      cout << endl;
      continue;
    }
    for (int i = 0; i < n + 5; i++) d[i].clear();
    for (int i = 0; i < n + 5; i++) vis[i] = 0;
    for (int i = 0; i < n + 5; i++) visited[i] = 0;
    for (int i = 0; i < n + 5; i++) color[i] = 0;
    for (int i = 0; i < m; i++) {
      cin >> x >> y;
      x--;
      y--;
      d[x].push_back(y);
      d[y].push_back(x);
    }
    for (int i = 0; i < n; i++) {
      c = check(i) && c;
      l[0] = l[1] = 0;
      long long t = bfs(i);
      if (l[0] && l[1])
        ans *= (po[l[0]] + po[l[1]]), ans = (ans % mod + mod) % mod;
      if ((l[1] == 1 && l[0] == 0) || l[0] == 1 && l[1] == 0)
        ans *= 3, ans = (ans % mod + mod) % mod;
    }
    if (c)
      cout << ans;
    else
      cout << 0;
    cout << endl;
  }
}
