#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (long long i = 0; i < v.size(); ++i) os << v[i] << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto it : v) os << it << " ";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << v.first << " " << v.second;
  return os;
}
const long long mod = 1e9 + 7;
const long long inf = 2e18;
const long long ninf = -2e18;
const long long p = 998244353;
long long visited[300005];
long long colour[300005];
vector<long long> g[300005];
bool isBipartite = true;
long long col1;
long long col2;
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  time_t t1, t2;
  t1 = clock();
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long ans = 1;
    for (long long i = 0; i <= n; i++) {
      visited[i] = 0;
      g[i].clear();
    }
    for (long long i = 0; i < m; i++) {
      long long a, b;
      cin >> a >> b;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    if (m == 0) {
      ans = pow(3, n, p);
    } else {
      isBipartite = true;
      for (long long j = 1; j <= n; j++) {
        if (visited[j] == 0) {
          col1 = 0;
          col2 = 0;
          long long col = 1;
          long long source = j;
          visited[source] = 1;
          queue<long long> q;
          q.push(source);
          colour[source] = col;
          col1++;
          while (!q.empty()) {
            long long curr = q.front();
            q.pop();
            vector<long long> neigh = g[curr];
            for (long long i = 0; i < neigh.size(); i++) {
              long long curn = neigh[i];
              col = colour[curr];
              if (!visited[curn]) {
                col *= -1;
                if (col == 1)
                  col1++;
                else
                  col2++;
                colour[curn] = col;
                q.push(curn);
                visited[curn] = 1;
              }
              if (colour[curn] == colour[curr]) {
                isBipartite = false;
              }
            }
          }
          if (isBipartite) {
            long long w = pow(2, col1, p) + pow(2, col2, p);
            w %= p;
            ans *= w;
            ans %= p;
          } else {
            ans = 0;
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
  t2 = clock();
  cerr << endl << t2 - t1 << endl;
  return 0;
}
