#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long cnt1 = 0, cnt2 = 0;
bool bfs(long long x, vector<vector<long long> > &v, vector<long long> &vis,
         vector<long long> &color) {
  queue<long long> q;
  q.push(x);
  vis[x] = 1;
  color[x] = 5;
  cnt1++;
  while (!q.empty()) {
    long long k = q.front();
    q.pop();
    for (long long i = 0; i < v[k].size(); i++) {
      if (color[v[k][i]] == 0) {
        if (color[k] == 5)
          color[v[k][i]] = 10;
        else
          color[v[k][i]] = 5;
      } else {
        if (color[v[k][i]] == color[k]) return false;
      }
      if (!vis[v[k][i]]) {
        vis[v[k][i]] = 1;
        q.push(v[k][i]);
        if (color[v[k][i]] == 10)
          cnt2++;
        else
          cnt1++;
      }
    }
  }
  return true;
}
long long power(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return power((x * x) % 998244353, n / 2);
  else
    return (x * power((x * x) % 998244353, (n - 1) / 2)) % 998244353;
}
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, x, y, flag = 0, ans = 1;
    cin >> n >> m;
    vector<vector<long long> > v(n + 1);
    vector<long long> vis(n + 1), color(n + 1);
    for (long long i = 0; i < m; i++) {
      cin >> x >> y;
      v[x].push_back(y);
      v[y].push_back(x);
    }
    for (long long i = 1; i <= n; i++) {
      if (!vis[i]) {
        bool p = bfs(i, v, vis, color);
        if (p == false) {
          flag = 1;
          cnt1 = 0;
          cnt2 = 0;
        } else {
          if (cnt2 == 0)
            ans = ((ans % 998244353) * 3) % 998244353;
          else {
            long long t;
            t = (power(2, cnt2) + power(2, cnt1)) % 998244353;
            ans = ((ans % 998244353) * (t % 998244353)) % 998244353;
          }
          cnt1 = 0;
          cnt2 = 0;
        }
      }
    }
    if (flag)
      cout << "0" << endl;
    else
      cout << ans << endl;
  }
}
