Beautiful Graph

Beautiful Graph

time limit per test2 seconds
memory limit per test256 megabytes

You are given an undirected unweighted graph consisting of n n n vertices and m edges.

You have to write a number on each vertex of the graph. Each number should be 1 , 2 o r 3 1, 2 or 3 1,2or3. The graph becomes beautiful if for each edge the sum of numbers on vertices connected by this edge is odd.

Calculate the number of possible ways to write numbers 1 , 2 1, 2 1,2 and 3 3 3 on vertices so the graph becomes beautiful. Since this number may be large, print it modulo 998244353 998244353 998244353.

Note that you have to write exactly one number on each vertex.

The graph does not have any self-loops or multiple edges.

Input

The first line contains one integer t ( 1 ≤ t ≤ 3 ⋅ 1 0 5 ) t (1≤t≤3⋅10^5) t(1t3105) — the number of tests in the input.

The first line of each test contains two integers n n n and m m m ( 1 ≤ n ≤ 3 ⋅ 1 0 5 , 0 ≤ m ≤ 3 ⋅ 1 0 5 ) (1≤n≤3⋅10^5,0≤m≤3⋅10^5) (1n3105,0m3105) — the number of vertices and the number of edges, respectively. Next m lines describe edges: i i i-th line contains two integers u i , v i ( 1 ≤ u i , v i ≤ n ; u i ≠ v i ) u_i, v_i (1≤u_i,v_i≤n;u_i≠v_i) ui,vi(1ui,vin;ui=vi)— indices of vertices connected by i-th edge.

It is guaranteed that ∑ i = 1 t n ≤ 3 ⋅ 1 0 5 \sum\limits_{i=1}^{t} n≤3⋅10^5 i=1tn3105 and ∑ i = 1 t m ≤ 3 ⋅ 1 0 5 \sum\limits_{i=1}^{t} m≤3⋅10^5 i=1tm3105.

Output

For each test print one line, containing one integer — the number of possible ways to write numbers 1 , 2 , 3 1, 2, 3 1,2,3 on the vertices of given graph so it becomes beautiful. Since answers may be large, print them modulo 998244353 998244353 998244353.

Example

input

2
2 1
1 2
4 6
1 2
1 3
1 4
2 3
2 4
3 4

output

4
0

Note

Possible ways to distribute numbers in the first test:

the vertex 1 1 1 should contain 1 1 1, and 2 2 2 should contain 2 2 2;
the vertex 1 1 1 should contain 3 3 3, and 2 2 2 should contain 2 2 2;
the vertex 1 1 1 should contain 2 2 2, and 2 2 2 should contain 1 1 1;
the vertex 1 1 1 should contain 2 2 2, and 2 2 2 should contain 3 3 3.
In the second test there is no way to distribute numbers.

/***  Amber  ***/
//#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
#define ls (rt<<1)
#define rs (rt<<1|1)
typedef long long ll;
template <typename T>
inline void read(T &x) {
    x = 0;
    static int p;
    p = 1;
    static char c;
    c = getchar();
    while (!isdigit(c)) {
        if (c == '-')p = -1;
        c = getchar();
    }
    while (isdigit(c)) {
        x = (x << 1) + (x << 3) + (c - 48);
        c = getchar();
    }
    x *= p;
}
template <typename T>
inline void print(T x) {
    if (x<0) {
        x = -x;
        putchar('-');
    }
    static int cnt;
    static int a[50];
    cnt = 0;
    do {
        a[++cnt] = x % 10;
        x /= 10;
    } while (x);
    for (int i = cnt; i >= 1; i--)putchar(a[i] + '0');
    puts("");
}
const double Pi=acos(-1);
const double eps=1e-6;
const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const ll Inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e6+10;

struct node{
    int v,nxt;
}e[maxn];
int t,head[maxn];
inline void add(int u,int v) {
    t++;
    e[t].v = v;
    e[t].nxt = head[u];
    head[u] = t;
}
int n,m,cnt1,cnt2,vis[maxn];
int flag;
void dfs(int u) {
    if (vis[u] == 1) cnt1++; else cnt2++;
    for (int i = head[u]; i; i = e[i].nxt) {
        int v = e[i].v;
        if (vis[v]) {
            if (vis[v]==vis[u]) flag = 1;
            continue;
        }
        vis[v] = 3 - vis[u];
        dfs(v);
    }
}
ll qpow(ll a,ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

inline void work() {
    read(n);
    t = 0;
    ll ans = 1;
    flag = 0;
    for (int i = 0; i <= n; i++) {
        vis[i] = 0;
        head[i] = 0;
    }
    read(m);
    for (int i = 1, u, v; i <= m; i++) {
        read(u);
        read(v);
        add(u, v);
        add(v, u);
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            vis[i] = 1;
            cnt1 = cnt2 = 0;
            dfs(i);
            if (flag) break;
            ans = ans * (qpow(2, cnt1) + qpow(2, cnt2)) % mod;
        }
    }
    if (flag) puts("0"); else printf("%lld\n", ans);
}
int main() {
    //freopen("1.txt","r",stdin);
    int T = 1;
    read(T);
    while (T--) {
        work();
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值