You are given two sets of integers: A and B. You need to output the sum of elements in the set C = \\{x | x = a ⊕ b, a ∈ A, b ∈ B\} modulo 998244353, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). Each number should be counted only once.

For example, if A = \{2, 3\} and B = \{2, 3\} you should count integer 1 only once, despite the fact that you can get it as 3 ⊕ 2 and as 2 ⊕ 3. So the answer for this case is equal to 1 + 0 = 1.

Let's call a segment [l; r] a set of integers \\{l, l+1, ..., r\}.

The set A is given as a union of n_A segments, the set B is given as a union of n_B segments.

Input

The first line contains a single integer n_A (1 ≤ n_A ≤ 100).

The i-th of the next n_A lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ 10^{18}), describing a segment of values of set A.

The next line contains a single integer n_B (1 ≤ n_B ≤ 100).

The i-th of the next n_B lines contains two integers l_j and r_j (1 ≤ l_j ≤ r_j ≤ 10^{18}), describing a segment of values of set B.

Note that segments in both sets may intersect.

Output

Print one integer — the sum of all elements in set C = \\{x | x = a ⊕ b, a ∈ A, b ∈ B\} modulo 998244353.

Examples

Input


2
3 5
5 8
3
1 2
1 9
2 9


Output


112


Input


1
1 9
2
2 4
2 10


Output


120

Note

In the second example, we can discover that the set C = \{0,1,...,15\}, which means that all numbers between 0 and 15 can be represented as a ⊕ b.
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long pot(long long a, int wyk) {
  long long ret = 1LL;
  while (wyk > 0) {
    if (wyk % 2 == 1) ret = a * ret % mod;
    a = a * a % mod;
    wyk /= 2;
  }
  return ret;
}
const int L = 61;
const int t = 20;
const int T = 1 << t;
vector<long long> A[2][L], Aux[2][L];
vector<pair<long long, long long> > dzialy;
void przelicz(int lvl, vector<long long> &w1, vector<long long> &w2) {
  for (auto pp : w1)
    for (auto q : w2) {
      auto p = pp;
      int l = lvl;
      p -= p & ((1LL << l) - 1);
      q -= q & ((1LL << l) - 1);
      long long pref = p ^ q;
      dzialy.push_back(make_pair(pref, pref + (1LL << l)));
    }
}
int main() {
  long long dwa = pot(2, mod - 2);
  for (int k = 0; k < 2; k++) {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
      long long a, b;
      scanf("%lld %lld", &a, &b);
      while (a <= b) {
        int l = 59;
        for (; l > 0; l--)
          if ((a & ((1LL << l) - 1)) == 0LL) {
            if (a + (1LL << l) <= b + 1LL) break;
          }
        A[k][l].push_back(a);
        a += (1LL << l);
      }
    }
    for (int i = 0; i < 60; i++) {
      if (!A[k][i].empty()) {
        sort(A[k][i].begin(), A[k][i].end());
        vector<long long> rob;
        rob.push_back(A[k][i][0]);
        for (int j = 1; j < (int)A[k][i].size(); j++)
          if (A[k][i][j - 1] < A[k][i][j]) {
            rob.push_back(A[k][i][j]);
          }
        A[k][i] = rob;
      }
      for (long long x : A[k][i]) {
        for (int j = i + 1; j < 60; j++) {
          long long pref = x;
          pref -= x & ((1LL << j) - 1);
          Aux[k][j].push_back(pref);
        }
      }
      if (!Aux[k][i].empty()) {
        sort(Aux[k][i].begin(), Aux[k][i].end());
        vector<long long> rob;
        rob.push_back(Aux[k][i][0]);
        for (int j = 1; j < (int)Aux[k][i].size(); j++)
          if (Aux[k][i][j - 1] < Aux[k][i][j]) {
            rob.push_back(Aux[k][i][j]);
          }
        Aux[k][i] = rob;
      }
    }
  }
  dzialy.reserve(1000000);
  for (int l = 0; l < 60; l++) {
    przelicz(l, A[1][l], Aux[0][l]);
    przelicz(l, A[0][l], Aux[1][l]);
    przelicz(l, A[0][l], A[1][l]);
  }
  sort(dzialy.begin(), dzialy.end());
  long long res = 0LL, from = 0LL;
  for (auto p : dzialy) {
    p.first = max(p.first, from);
    if (p.second > p.first) {
      res += (p.first + p.second - 1LL) % mod * ((p.second - p.first) % mod) %
             mod * dwa % mod;
      res %= mod;
    }
    from = max(from, p.second);
  }
  printf("%lld\n", res);
}
