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 int N = 105;
const int LOG = 61;
const int M = 2 * N * LOG * 4;
const long long lim = ((long long)1 << 60) - 1;
vector<int> nds[2][LOG];
int ls[M], rs[M], tsz, root[2], mark[M];
long long L[M], R[M];
void Add(int t, int &c, long long ss, long long se, long long qs, long long qe,
         int dep) {
  if (qs > qe || qs > se || ss > qe) return;
  if (!c) c = ++tsz, nds[t][dep].push_back(c), L[c] = ss, R[c] = se;
  if (qs <= ss && qe >= se) {
    mark[c] = 1;
    return;
  }
  long long mid = ss + se >> 1;
  Add(t, ls[c], ss, mid, qs, qe, dep + 1);
  Add(t, rs[c], mid + 1, se, qs, qe, dep + 1);
}
void rd(int t) {
  int n;
  scanf("%i", &n);
  while (n--) {
    long long l, r;
    scanf("%lld %lld", &l, &r);
    Add(t, root[t], 0, lim, l, r, 0);
  }
}
const int H = 16 * N * N * LOG;
pair<long long, long long> seg[H];
int xb;
const int mod = 998244353;
long long gt(long long x) {
  x %= mod;
  return x * (x + 1) % mod * ((mod + 1) / 2) % mod;
}
long long gt(long long r, long long l) { return gt(r) + mod - gt(l); }
int main() {
  rd(0);
  rd(1);
  for (int i = 0; i < LOG; i++) {
    for (int a : nds[0][i])
      for (int b : nds[1][i])
        if (mark[a] || mark[b]) seg[++xb] = {L[a] ^ L[b], L[a] ^ R[b]};
  }
  sort(seg + 1, seg + 1 + xb);
  long long ans = 0, r = -1;
  for (int i = 1; i <= xb; i++) {
    if (seg[i].second > r)
      ans += gt(seg[i].second, max(r, seg[i].first - 1)), ans %= mod;
    r = max(r, seg[i].second);
  }
  printf("%lld\n", ans);
  return 0;
}
