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;
struct itv {
  long long l, r;
  int sum() const {
    if ((l + r) & 1)
      return ((((r - l + 1) / 2) % 998244353) * ((l + r) % 998244353)) %
             998244353;
    return ((((l + r) / 2) % 998244353) * ((r - l + 1) % 998244353)) %
           998244353;
  }
};
struct pii {
  int l, r;
  pii() : l(0), r(0) {}
};
bool operator<(const itv &a, const itv &b) {
  if (a.l != b.l) return a.l < b.l;
  return a.r > b.r;
}
int bitn(long long x, int n) { return (x >> n) & 1; }
int n[2];
itv a[2][100 + 1];
pii have[2][100 + 1];
std::vector<itv> rslt;
void fdb() {}
int main() {
  for (int z = 0; z < 2; ++z) {
    cin >> n[z];
    for (int i = 1; i <= n[z]; ++i) cin >> a[z][i].l >> a[z][i].r;
  }
  int ans = 0;
  std::vector<long long> vt1, vt2;
  for (int b = 0; b <= 60; ++b) {
    for (int x = 0; x < 2; ++x)
      for (int i = 1; i <= n[x]; ++i) {
        vt1.clear();
        if (a[x][i].l <= a[x][i].r) {
          if (bitn(a[x][i].l, b)) vt1.emplace_back(a[x][i].l);
          if (!bitn(a[x][i].r, b)) vt1.emplace_back(a[x][i].r + 1 - (1ll << b));
        }
        for (int j = 1; j <= n[!x]; ++j) {
          vt2.clear();
          if (a[!x][j].l <= a[!x][j].r) {
            if (bitn(a[!x][j].l, b)) vt2.emplace_back(a[!x][j].l);
            if (!bitn(a[!x][j].r, b))
              vt2.emplace_back(a[!x][j].r + 1 - (1ll << b));
            if (have[!x][j].l) vt2.emplace_back(a[!x][j].l - (1ll << b));
            if (have[!x][j].r) vt2.emplace_back(a[!x][j].r + 1);
          } else {
            if (bitn(a[!x][j].l, b) == bitn(a[!x][j].r, b))
              vt2.emplace_back(a[!x][j].r & (~((1ll << b) - 1)));
            else {
              if (have[!x][j].l) vt2.emplace_back(a[!x][j].l - (1ll << b));
              if (have[!x][j].r) vt2.emplace_back(a[!x][j].r + 1);
            }
          }
          for (auto i1 : vt1)
            for (auto i2 : vt2) {
              if ((i1 ^ i2) < 0) fdb();
              rslt.push_back({i1 ^ i2, (i1 ^ i2) + (1ll << b) - 1});
            }
        }
      }
    for (int x = 0; x < 2; ++x)
      for (int i = 1; i <= n[x]; ++i)
        if (a[x][i].l <= a[x][i].r) {
          if (bitn(a[x][i].l, b)) {
            have[x][i].l = 1;
            a[x][i].l += 1ll << b;
          }
          if (!bitn(a[x][i].r, b)) {
            have[x][i].r = 1;
            a[x][i].r -= 1ll << b;
          }
        }
  }
  std::sort(rslt.begin(), rslt.end());
  for (int i = 0; i < rslt.size();) {
    ans = (ans + rslt[i].sum()) % 998244353;
    for (long long r = rslt[i].r; i < rslt.size() && rslt[i].r <= r; ++i)
      ;
  }
  cout << ans;
  return 0;
}
