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>
template <class T>
inline void read(T &res) {
  res = 0;
  bool bo = 0;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    bo = 1;
  else
    res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + (c - 48);
  if (bo) res = ~res + 1;
}
const int N = 105, M = 5e4 + 5, L = 4e6 + 5, rqy = 998244353, I2 = 499122177;
const long long ET = (1ll << 60) - 1;
int n, na, nb, ans;
struct seg {
  int rt, lc[M], rc[M], dep[M], ToT;
  bool mark[M];
  long long num[M];
  void orznc(int T, long long l, long long r, long long s, long long e,
             long long x, int &p) {
    if (e < l || s > r) return;
    if (!p) dep[p = ++ToT] = T, num[p] = x;
    if (s <= l && r <= e) return (void)(mark[p] = 1);
    long long mid = l + r >> 1;
    orznc(T - 1, l, mid, s, e, x, lc[p]);
    orznc(T - 1, mid + 1, r, s, e, x | (1ll << T - 1), rc[p]);
  }
} A, B;
struct elem {
  int dep;
  long long num;
} a[L];
inline bool comp(elem a, elem b) {
  return a.num < b.num || (a.num == b.num && a.dep > b.dep);
}
int main() {
  long long l, r, lst = -1;
  int d;
  read(na);
  while (na--) read(l), read(r), A.orznc(60, 0, ET - 1, l, r, 0, A.rt);
  read(nb);
  while (nb--) read(l), read(r), B.orznc(60, 0, ET - 1, l, r, 0, B.rt);
  for (int p = 1; p <= A.ToT; p++)
    for (int q = 1; q <= B.ToT; q++)
      if (A.dep[p] == B.dep[q] && (A.mark[p] || B.mark[q])) {
        int T = A.dep[p];
        a[++n] = (elem){T, A.num[p] ^ B.num[q]};
      }
  std::sort(a + 1, a + n + 1, comp);
  for (int i = 1; i <= n; i++) {
    if (lst != -1 && d >= a[i].dep && (lst >> d) == (a[i].num >> d)) continue;
    d = a[i].dep;
    lst = a[i].num;
    ans = (lst % rqy * ((1ll << d) % rqy) + ans) % rqy;
    ans =
        (((1ll << d) % rqy) * (((1ll << d) - 1) % rqy) % rqy * I2 + ans) % rqy;
  }
  return std::cout << ans << std::endl, 0;
}
