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;
inline long long read() {
  char ch = getchar();
  long long nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  long long ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
inline long long add(long long x, long long y) {
  return x + y >= 998244353 ? x + y - 998244353 : x + y;
}
inline long long add(long long x, long long y, long long z) {
  return add(add(x, y), z);
}
inline long long sub(long long x, long long y) {
  return x - y < 0 ? x - y + 998244353 : x - y;
}
inline long long mul(long long x, long long y) {
  return 1LL * x * y % 998244353;
}
inline long long mul(long long x, long long y, long long z) {
  return mul(mul(x, y), z);
}
long long qpow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = mul(ans, x);
    x = mul(x, x);
    y >>= 1;
  }
  return ans;
}
long long Inv(long long x) { return qpow(x, 998244353 - 2); }
vector<pair<long long, long long> > Merge(
    vector<pair<long long, long long> > a) {
  long long n = a.size();
  for (long long i = 0; i < (long long)a.size(); i++) a[i].second++;
  vector<long long> t(n * 2), v(n * 2);
  for (long long i = 0; i < (long long)a.size(); i++)
    t[i * 2] = a[i].first, t[i * 2 + 1] = a[i].second;
  sort(t.begin(), t.end());
  t.erase(unique(t.begin(), t.end()), t.end());
  for (long long i = 0; i < (long long)a.size(); i++)
    a[i].first = lower_bound(t.begin(), t.end(), a[i].first) - t.begin();
  for (long long i = 0; i < (long long)a.size(); i++)
    a[i].second = lower_bound(t.begin(), t.end(), a[i].second) - t.begin();
  for (long long i = 0; i < (long long)a.size(); i++)
    v[a[i].first]++, v[a[i].second]--;
  for (long long i = 1; i < (long long)t.size(); i++) v[i] += v[i - 1];
  vector<pair<long long, long long> > ans;
  for (long long i = 0; i < (long long)t.size(); i++) {
    if (!v[i]) continue;
    long long r = i;
    while (v[r]) r++;
    ans.emplace_back(t[i], t[r] - 1);
    i = r;
  }
  return ans;
}
vector<pair<long long, long long> > a, b;
long long n, m, I = Inv(2);
struct Node {
  long long v, ls, rs;
};
Node t[105 * 1005];
long long cnt, rtA, rtB;
void build(long long &u, long long l, long long r, long long L, long long R) {
  if (!u) u = ++cnt;
  if (L <= l && r <= R) {
    t[u].v = 1;
    return;
  }
  long long mid = (l + r) / 2;
  if (mid >= L) build(t[u].ls, l, mid, L, R);
  if (mid < R) build(t[u].rs, mid + 1, r, L, R);
}
long long ans = 0;
void query(vector<pair<long long, long long> > q, long long l, long long r) {
  if (q.empty()) return;
  for (auto [u, v] : q) {
    if (t[u].v || t[v].v) {
      ans = add(ans, mul((r - l + 1) % 998244353, (l + r) % 998244353, I));
      return;
    }
  }
  long long mid = (l + r) / 2;
  vector<pair<long long, long long> > q1, q2;
  for (auto [u, v] : q) {
    if (t[u].ls && t[v].ls) q1.emplace_back(t[u].ls, t[v].ls);
    if (t[u].rs && t[v].rs) q1.emplace_back(t[u].rs, t[v].rs);
    if (t[u].rs && t[v].ls) q2.emplace_back(t[u].rs, t[v].ls);
    if (t[u].ls && t[v].rs) q2.emplace_back(t[u].ls, t[v].rs);
  }
  query(q1, l, mid), query(q2, mid + 1, r);
}
signed main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long l = read(), r = read();
    a.emplace_back(l, r);
  }
  cin >> m;
  for (long long i = 1; i <= m; i++) {
    long long l = read(), r = read();
    b.emplace_back(l, r);
  }
  a = Merge(a), b = Merge(b);
  for (auto [l, r] : a) build(rtA, 0, ((1LL << 60) - 1), l, r);
  for (auto [l, r] : b) build(rtB, 0, ((1LL << 60) - 1), l, r);
  query({make_pair(rtA, rtB)}, 0, ((1LL << 60) - 1));
  cout << ans << endl;
  return 0;
}
