#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  if (a == 0ll) {
    return 0ll;
  }
  a %= MOD;
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return ans;
}
long long poww(long long a, long long b) {
  if (a == 0ll) {
    return 0ll;
  }
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a;
    }
    a = a * a;
    b >>= 1;
  }
  return ans;
}
void Pv(const vector<int> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%d", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
void Pvl(const vector<long long> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%lld", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
inline long long readll() {
  long long tmp = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar();
  return tmp * fh;
}
inline int readint() {
  int tmp = 0, fh = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') fh = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar();
  return tmp * fh;
}
void pvarr_int(int *arr, int n, int strat = 1) {
  if (strat == 0) {
    n--;
  }
  for (int i = strat; i <= n; i++) {
    printf("%d%c", arr[i], i == n ? '\n' : ' ');
  }
}
void pvarr_LL(long long *arr, int n, int strat = 1) {
  if (strat == 0) {
    n--;
  }
  for (int i = strat; i <= n; i++) {
    printf("%lld%c", arr[i], i == n ? '\n' : ' ');
  }
}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
int n, m;
std::vector<int> e[maxn];
int col[maxn];
const long long mod = 998244353;
int main() {
  int t;
  t = readint();
  while (t--) {
    n = readint();
    m = readint();
    while (m--) {
      int x = readint();
      int y = readint();
      e[x].push_back(y);
      e[y].push_back(x);
    }
    int isok = 1;
    queue<pair<int, int> > q;
    long long ans = 1ll;
    for (int i = 1; i <= n; i++) {
      if (col[i] != 0) {
        continue;
      }
      int cnt1 = 0;
      int cnt2 = 0;
      q.push(make_pair(i, 1));
      while (!q.empty()) {
        pair<int, int> temp = q.front();
        q.pop();
        if (col[temp.first] != 0 && col[temp.first] != temp.second) {
          isok = 0;
          break;
        }
        if (col[temp.first] == 0) {
          if (temp.second == 1) {
            cnt1++;
          } else {
            cnt2++;
          }
          col[temp.first] = temp.second;
        } else {
          continue;
        }
        for (auto Z : e[temp.first]) {
          q.push(make_pair(Z, temp.second == 1 ? 2 : 1));
        }
      }
      long long temp = 0ll;
      temp += powmod(2ll, cnt1, mod);
      temp += powmod(2ll, cnt2, mod);
      temp %= mod;
      ans = ans * temp % mod;
    }
    if (isok) {
      printf("%lld\n", ans);
    } else {
      printf("0\n");
    }
    for (int i = 1; i <= n; i++) {
      col[i] = 0;
      e[i].clear();
    }
  }
  return 0;
}
