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 mxN = 100, M = 998244353;
const long long P = 1ll << 60;
int n1, n2;
long long l1[mxN], r1[mxN], l2[mxN], r2[mxN], ans;
vector<array<long long, 2>> v;
void ins(long long l, long long a, bool b) {
  if (b) {
    v.push_back({l, 1});
    v.push_back({l + a, -1});
  } else {
    v.push_back({P - l - a, 1});
    v.push_back({P - l, -1});
  }
}
void pr(long long l1, long long a1, long long l2, long long a2, bool b) {
  if (a1 < 0 || a2 < 0) return;
  for (int i = 59; ~i; --i) {
    if (a1 < 1ll << i && a2 < 1ll << i) continue;
    if (a1 >= 1ll << i && a2 >= 1ll << i) {
      ins((l1 ^ l2) & ~((1ll << i + 1) - 1), 1ll << i + 1, b);
      return;
    }
    ins((l1 ^ l2) & ~((1ll << i) - 1), 1ll << i, b);
    if (a1 >= 1ll << i) {
      l1 ^= 1ll << i;
      a1 ^= 1ll << i;
    }
    if (a2 >= 1ll << i) {
      l2 ^= 1ll << i;
      a2 ^= 1ll << i;
    }
  }
  ins(l1 ^ l2, 1, b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n1;
  for (int i = 0; i < n1; ++i) cin >> l1[i] >> r1[i];
  cin >> n2;
  for (int i = 0; i < n2; ++i) cin >> l2[i] >> r2[i];
  for (int i = 0; i < n1; ++i) {
    for (int j = 0; j < n2; ++j) {
      long long m1 = r1[i] &
                     ~(l1[i] < r1[i]
                           ? ((1ll << 63 - __builtin_clzll(l1[i] ^ r1[i])) - 1)
                           : 0),
                m2 = r2[j] &
                     ~(l2[j] < r2[j]
                           ? ((1ll << 63 - __builtin_clzll(l2[j] ^ r2[j])) - 1)
                           : 0);
      pr(m1, r1[i] - m1, m2, r2[j] - m2, 1);
      pr(m1, r1[i] - m1, P - m2, m2 - l2[j] - 1, 0);
      pr(P - m1, m1 - l1[i] - 1, m2, r2[j] - m2, 0);
      pr(P - m1, m1 - l1[i] - 1, P - m2, m2 - l2[j] - 1, 1);
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0, c = 0; i < v.size(); ++i) {
    if (!c) ans += M - (v[i][0] % M) * ((v[i][0] - 1) % M) % M;
    c += v[i][1];
    if (!c) ans += (v[i][0] % M) * ((v[i][0] - 1) % M) % M;
  }
  cout << ans % M * 499122177 % M;
}
