Problem: You are given a bipartite graph consisting of n_1 vertices in the first part, n_2 vertices in the second part, and m edges, numbered from 1 to m. You have to color each edge into one of two colors, red and blue. You have to minimize the following value: ∑ _{v ∈ V} |r(v) - b(v)|, where V is the set of vertices of the graph, r(v) is the number of red edges incident to v, and b(v) is the number of blue edges incident to v.

Sounds classical and easy, right? Well, you have to process q queries of the following format:

  * 1 v_1 v_2 — add a new edge connecting the vertex v_1 of the first part with the vertex v_2 of the second part. This edge gets a new index as follows: the first added edge gets the index m + 1, the second — m + 2, and so on. After adding the edge, you have to print the hash of the current optimal coloring (if there are multiple optimal colorings, print the hash of any of them). Actually, this hash won't be verified, you may print any number as the answer to this query, but you may be asked to produce the coloring having this hash; 
  * 2 — print the optimal coloring of the graph with the same hash you printed while processing the previous query. The query of this type will only be asked after a query of type 1, and there will be at most 10 queries of this type. If there are multiple optimal colorings corresponding to this hash, print any of them. 



Note that if an edge was red or blue in some coloring, it may change its color in next colorings.

The hash of the coloring is calculated as follows: let R be the set of indices of red edges, then the hash is (∑ _{i ∈ R} 2^i) mod 998244353.

Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query. Use functions fflush in C++ and BufferedWriter.flush in Java languages after each writing in your program.

Input

The first line contains three integers n_1, n_2 and m (1 ≤ n_1, n_2, m ≤ 2 ⋅ 10^5).

Then m lines follow, the i-th of them contains two integers x_i and y_i (1 ≤ x_i ≤ n_1; 1 ≤ y_i ≤ n_2) meaning that the i-th edge connects the vertex x_i from the first part and the vertex y_i from the second part.

The next line contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries you have to process.

The next q lines contain the queries in the format introduced in the statement.

Additional constraints on the input:

  * at any moment, the graph won't contain any multiple edges; 
  * the queries of type 2 are only asked if the previous query had type 1; 
  * there are at most 10 queries of type 2. 

Output

To answer a query of type 1, print one integer — the hash of the optimal coloring.

To answer a query of type 2, print one line. It should begin with the integer k — the number of red edges. Then, k distinct integer should follow — the indices of red edges in your coloring, in any order. Each index should correspond to an existing edge, and the hash of the coloring you produce should be equal to the hash you printed as the answer to the previous query.

If there are multiple answers to a query, you may print any of them.

Example

Input


3 4 2
1 2
3 4
10
1 1 3
1 2 3
2
1 3 3
2
1 2 4
2
1 2 1
1 1 1
2


Output


8
8
1 3
40
2 3 5
104
3 5 6 3
104
360
4 5 6 3 8

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const uint64_t seed = std::chrono::system_clock::now().time_since_epoch().count();
mt19937_64 rnd(seed);
const int MOD = 998244353;

#ifdef VIPJML_LOCAL
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << "{";
    for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << *vi;
    }
    os << "}";
    return os;
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const vector<pair<A, B>> &v)
{
    os << "{";
    for (typename vector<pair<A, B>>::const_iterator vi = v.begin(); vi != v.end(); ++vi)
    {
        if (vi != v.begin())
            os << ", ";
        os << '(' << vi->first << " " << vi->second << ")";
    }
    os << "}";
    return os;
}

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
using LL = long long;

struct Mint
{
    long long v;
    Mint() : v(0) {}
    Mint(long long t)
    {
        v = t % MOD;
        if (v < 0)
            v += MOD;
    }

    Mint pow(long long k)
    {
        Mint res(1), tmp(v);
        while (k)
        {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    Mint inv() { return pow(MOD - 2); }

    Mint &operator+=(Mint a)
    {
        v += a.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    Mint &operator-=(Mint a)
    {
        v += MOD - a.v;
        if (v >= MOD)
            v -= MOD;
        return *this;
    }
    Mint &operator*=(Mint a)
    {
        v = v * a.v % MOD;
        return *this;
    }
    Mint &operator/=(Mint a) { return (*this) *= a.inv(); }

    Mint operator+(Mint a) const { return Mint(v) += a; }
    Mint operator-(Mint a) const { return Mint(v) -= a; }
    Mint operator*(Mint a) const { return Mint(v) *= a; }
    Mint operator/(Mint a) const { return Mint(v) /= a; }

    Mint operator-() const { return v ? Mint(MOD - v) : Mint(v); }

    bool operator==(const Mint a) const { return v == a.v; }
    bool operator!=(const Mint a) const { return v != a.v; }
    bool operator<(const Mint a) const { return v < a.v; }

    static Mint comb(long long n, int k)
    {
        Mint num(1), dom(1);
        for (int i = 0; i < k; i++)
        {
            num *= Mint(n - i);
            dom *= Mint(i + 1);
        }
        return num / dom;
    }

    static Mint inv(int n)
    {
        return Mint(n).inv();
    }

    static vector<Mint> getInvArray(int N)
    {
        vector<Mint> inv(N + 1, 1);
        for (int i = 2; i <= N; i++)
            inv[i] = inv[MOD % i] * (MOD - MOD / i);
        return inv;
    }
};

ostream &operator<<(ostream &os, Mint m)
{
    os << m.v;
    return os;
}

void solve(int caseNum)
{
    int n1, n2, m;
    cin >> n1 >> n2 >> m;
    int n = n1 + n2;
    vector<pair<int, int>> e;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        y += n1;
        g[x].push_back(i);
        g[y].push_back(i);
        e.push_back({x, y});
        //dbg(x, y);
    }

    struct EPATH
    {
        unordered_set<int> e1;
        unordered_set<int> e2;
        Mint total = 0;
        Mint cur = 0;
        int cnt = 0;
        int startP;
        int lastP;
        EPATH()
        {
        }
    };
    Mint ans = 0;
    vector<Mint> pp(4e5 + 1, 1);
    for (int i = 1; i <= 4e5; i++)
    {
        pp[i] = pp[i - 1] * 2;
    }

    vector<int> cur(n, 0);
    vector<bool> used(m, false);
    vector<int> ecnt(n);
    for (int i = 0; i < n; i++)
        ecnt[i] = g[i].size();

    vector<EPATH> path;
    function<void(int, int)> dfs = [&](int c, int i) {
        for (; cur[c] < g[c].size(); cur[c]++)
        {
            int ei = g[c][cur[c]];
            if (used[ei])
                continue;
            used[ei] = true;
            ecnt[e[ei].first]--;
            ecnt[e[ei].second]--;
            path[i].cnt++;
            path[i].total += pp[ei + 1];
            if (path[i].cnt % 2 == 0)
            {
                path[i].cur += pp[ei + 1];
                path[i].e2.insert(ei);
            }
            else
            {
                path[i].e1.insert(ei);
            }
            if (path[i].cnt == 1)
                path[i].startP = c;
            dfs(c ^ e[ei].first ^ e[ei].second, i);
            return;
        }
        path[i].lastP = c;
    };
    for (int i = 0; i < n; i++)
    {
        if (ecnt[i] % 2 == 1)
        {
            path.emplace_back();
            dfs(i, path.size() - 1);
        }
    }
    int ps = path.size();
    for (int i = 0; i < n; i++)
    {
        if (ecnt[i] != 0)
        {
            path.emplace_back();
            dfs(i, path.size() - 1);
        }
    }
    dbg(ps, path.size());
    auto reversePath = [&](int i) {
        swap(path[i].startP, path[i].lastP);
        if (path[i].cnt % 2 == 0)
        {
            ans -= path[i].cur;
            path[i].cur = path[i].total - path[i].cur;
            ans += path[i].cur;
            swap(path[i].e1, path[i].e2);
        }
    };
    unordered_map<int, int> pMap;
    for (int i = 0; i < path.size(); i++)
    {
        EPATH &ep = path[i];
        if (i < ps)
        {
            pMap[ep.startP] = i;
            pMap[ep.lastP] = i;
        }
        ans += ep.cur;
    }
    auto dbgPath = [&]() {
        for (auto t : path)
        {
            dbg(vector<int>(t.e1.begin(), t.e1.end()));
            dbg(vector<int>(t.e2.begin(), t.e2.end()));
        }
    };
    //dbgPath();
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int t, u, v;
        cin >> t;
        if (t == 1)
        {
            cin >> u >> v;
            u--, v--;
            v += n1;
            int p1 = -1, p2 = -1;
            if (pMap.find(u) != pMap.end())
                p1 = pMap[u];
            if (pMap.find(v) != pMap.end())
                p2 = pMap[v];

            if (p1 == -1 && p2 == -1)
            {
                path.emplace_back();
                path.back().e1.insert(m);
                path.back().cnt = 1;
                path.back().cur = 0;
                path.back().total = pp[m + 1];
                path.back().startP = u;
                path.back().lastP = v;
                pMap[u] = path.size() - 1;
                pMap[v] = path.size() - 1;
            }
            else
            {
                if (p2 == -1)
                {
                    swap(p1, p2);
                    swap(u, v);
                }

                if (p1 == -1)
                {
                    if (path[p2].startP == v)
                        reversePath(p2);
                    path[p2].cnt++;
                    path[p2].total += pp[m + 1];
                    pMap.erase(v);
                    pMap[u] = p2;

                    if (path[p2].cnt % 2 == 0)
                    {
                        path[p2].cur += pp[m + 1];
                        path[p2].e2.insert(m);
                        ans += pp[m + 1];
                    }
                    else
                    {
                        path[p2].e1.insert(m);
                    }
                    path[p2].lastP = u;
                }
                else
                {
                    pMap.erase(u);
                    pMap.erase(v);
                    if (p1 == p2)
                    {
                        path[p2].cnt++;
                        path[p2].total += pp[m + 1];
                        path[p2].cur += pp[m + 1];
                        ans += pp[m + 1];
                        path[p2].e2.insert(m);
                        path[p2].lastP = path[p2].startP;
                    }
                    else
                    {
                        if (path[p1].e1.size() < path[p2].e1.size())
                        {
                            swap(p1, p2);
                            swap(u, v);
                        }
                        if (path[p1].startP == u)
                            reversePath(p1);
                        if (path[p2].lastP == v)
                            reversePath(p2);
                        path[p1].total += pp[m + 1] + path[p2].total;
                        if (path[p1].cnt % 2 == 1)
                        {
                            path[p1].e2.insert(m);
                            path[p1].e1.insert(path[p2].e1.begin(), path[p2].e1.end());
                            path[p1].e2.insert(path[p2].e2.begin(), path[p2].e2.end());
                            path[p1].cur += pp[m + 1] + path[p2].cur;
                            ans += pp[m + 1];
                        }
                        else
                        {
                            path[p1].e1.insert(m);
                            path[p1].e1.insert(path[p2].e2.begin(), path[p2].e2.end());
                            path[p1].e2.insert(path[p2].e1.begin(), path[p2].e1.end());
                            ans -= path[p1].cur + path[p2].cur;
                            path[p1].cur += path[p2].total - path[p2].cur;
                            ans += path[p1].cur;
                        }
                        path[p1].lastP = path[p2].lastP;
                        pMap[path[p2].lastP] = p1;
                        path[p1].cnt += 1 + path[p2].cnt;
                        path[p2].e1.clear();
                        path[p2].e2.clear();
                    }
                }
            }
            m++;
            cout << ans << endl;
            //dbgPath();
        }
        else
        {
            vector<int> res;
            for (auto &ep : path)
            {
                for (int ei : ep.e2)
                {
                    res.push_back(ei);
                }
            }
            cout << res.size() << " ";
            for (int r : res)
                cout << r + 1 << " ";
            cout << endl;
        }
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    int T = 1;
    //cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve(i);
    }
    cout.flush();
    return 0;
}