Under construction

Still being built. Things may change

Triangular Cactus Paths

Time limit2sMemory limit1024 MB

Summary
Count simple paths of exact length k between s and f in a triangular cactus graph for each query, modulo 998244353.
Level

Hard8 of 10

Topics
Graph, Tree, Dynamic programming
Solved
No attempts yet

Problem

You are given a simple connected undirected graph that is a cactus: each edge lies on at most one simple cycle. This cactus is triangular: the length of any simple cycle is at most 33.

Answer the queries. In each query, you are given two vertices ss and ff, and an integer kk. Find the number of simple paths between vertices ss and ff with length exactly kk. You should find this number modulo 998 244 353998\,244\,353.

The path is simple if all its vertices are different. The length of the path is the number of edges on the path.

Input

The first line contains two integers nn, mm (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5, n−1≤m≤3(n−1)2n - 1 \leq m \leq \frac{3(n-1)}{2}), the number of vertices and edges in the graph.

Each of the next mm lines contains two integers uu, vv (1≤u,v≤n1 \leq u, v \leq n, u≠vu \neq v), meaning that there is an undirected edge (u,v)(u, v) in the graph. All edges are different. It is guaranteed that the graph is a connected triangular cactus.

The next line contains a single integer qq (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5), the number of queries.

Each of the next qq lines contains three integers ss, ff, kk (1≤s,f≤n1 \leq s, f \leq n, 0≤k<n0 \leq k < n), describing a query.

Output

Print qq integers, one answer per query.

Examples1

  1. Example 1

    Input
    8 10
    1 2
    2 3
    3 1
    3 4
    4 5
    5 6
    6 4
    4 7
    7 8
    8 4
    6
    1 1 0
    1 1 1
    1 4 3
    6 2 4
    5 7 4
    3 4 2
    
    Expected output
    1
    0
    1
    2
    1
    0