#include <bits/stdc++.h>
using namespace std;
long long expo(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      res = (res * a) % 998244353;
    }
    b /= 2;
    a = (a * a) % 998244353;
  }
  return res;
}
bool exitt = 0;
long long oddcount = 0;
long long evencount = 0;
void dfs(long long node, vector<vector<long long> > &adj,
         vector<long long> &odd, vector<long long> &even, long long parity) {
  if (even[node] == 1 && odd[node] == 1) {
    exitt = 1;
    return;
  }
  for (auto k : adj[node]) {
    if ((parity + 1) % 2 == 1) {
      if (odd[k] == 0) {
        odd[k] = 1;
        oddcount++;
        dfs(k, adj, odd, even, 1);
      }
    } else {
      if (even[k] == 0) {
        even[k] = 1;
        evencount++;
        dfs(k, adj, odd, even, 0);
      }
    }
  }
  return;
}
void find() {
  long long no_of_vertex, no_of_edge;
  cin >> no_of_vertex >> no_of_edge;
  long long input1, input2;
  vector<vector<long long> > adj(no_of_vertex + 1);
  for (long long i = 0; i < no_of_edge; i++) {
    cin >> input1 >> input2;
    adj[input1].push_back(input2);
    adj[input2].push_back(input1);
  }
  vector<long long> odd(no_of_vertex + 1, 0);
  vector<long long> even(no_of_vertex + 1, 0);
  vector<long long> ans;
  for (long long i = 1; i <= no_of_vertex; i++) {
    if (odd[i] == 0 && even[i] == 0) {
      dfs(i, adj, odd, even, 0);
      if (exitt == 1) {
        exitt = 0;
        oddcount = 0;
        evencount = 0;
        cout << 0;
        return;
      }
      if (oddcount == 0 && evencount == 0) {
        ans.push_back(3);
      } else {
        ans.push_back((expo(2, evencount) + expo(2, oddcount)) % 998244353);
      }
      oddcount = 0;
      evencount = 0;
    }
  }
  long long res = 1;
  for (long long i = 0; i < ans.size(); i++) {
    res *= ans[i];
    res %= 998244353;
  }
  cout << res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long no_of_input;
  cin >> no_of_input;
  for (long long i = 0; i < no_of_input; i++) {
    find();
    cout << "\n";
  }
}
