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;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
int n;
vector<pair<int, int> > ve[62];
struct node {
  int root, tot;
  int ch[100010][2];
  bool tag[100010];
  void insert(long long L, long long R, long long l, long long r, int &x) {
    if (!x) x = ++tot;
    if (L <= l && R >= r) {
      tag[x] = true;
      return;
    }
    if (L <= ((l + r) >> 1)) insert(L, R, l, ((l + r) >> 1), ch[x][0]);
    if (R > ((l + r) >> 1)) insert(L, R, ((l + r) >> 1) + 1, r, ch[x][1]);
  }
} A, B;
long long dfs(int d, long long v) {
  for (int i = 0; i < ve[d].size(); ++i) {
    pair<int, int> t = ve[d][i];
    if (A.tag[t.first] || B.tag[t.second])
      return (v +
              ((((long long)1 << d) - 1) % 998244353) * 499122177 % 998244353) %
             998244353 * (((long long)1 << d) % 998244353) % 998244353;
  }
  long long val = 0;
  for (int x = 0; x <= 1; ++x) {
    ve[d - 1].clear();
    for (int i = 0; i < ve[d].size(); ++i) {
      pair<int, int> t = ve[d][i];
      for (int y = 0; y <= 1; ++y)
        if (A.ch[t.first][y] && B.ch[t.second][x ^ y])
          ve[d - 1].push_back(
              make_pair(A.ch[t.first][y], B.ch[t.second][x ^ y]));
    }
    if (ve[d - 1].size())
      val = (val + dfs(d - 1, v | ((long long)x << (d - 1)))) % 998244353;
  }
  return val;
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    long long l, r;
    read(l), read(r);
    A.insert(l, r, 0, ((long long)1 << 60) - 1, A.root);
  }
  read(n);
  for (int i = 1; i <= n; ++i) {
    long long l, r;
    read(l), read(r);
    B.insert(l, r, 0, ((long long)1 << 60) - 1, B.root);
  }
  ve[60].push_back(make_pair(A.root, B.root)), printf("%lld", dfs(60, 0));
  return 0;
}
