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 INF = 1000 * 1000 * 1000;
const int mod = 998244353;
const int dwa = (mod + 1) / 2;
string s[1005];
int add(long long a, long long b) {
  a %= mod;
  b %= mod;
  return a + b >= mod ? a + b - mod : a + b;
}
int mult(long long a, long long b) {
  a %= mod;
  b %= mod;
  return a * (long long)b % mod;
}
int sum(long long l, long long r) {
  return mult(l + r, mult((r - l + 1), dwa));
}
vector<pair<long long, long long> > seg[2], seg3;
void split(long long tl, long long tr, long long l, long long r, int it,
           vector<pair<long long, long long> > &v) {
  if (l > r) return;
  if (tl == l && tr == r) {
    v.push_back({tl, it});
    return;
  }
  long long tm = (tl + tr) / 2;
  split(tl, tm, l, min(r, tm), it - 1, v);
  split(tm + 1, tr, max(l, tm + 1), r, it - 1, v);
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second > b.second;
}
vector<pair<long long, long long> > reb(vector<pair<long long, long long> > v) {
  sort(v.begin(), v.end(), cmp);
  long long r = -1;
  vector<pair<long long, long long> > w;
  for (auto first : v)
    if (first.first + (1LL << first.second) - 1 > r) {
      w.push_back(first);
      r = first.first + (1LL << first.second) - 1;
    }
  return w;
}
int n[2];
int main() {
  for (int i = 0; i < 2; i++) {
    cin >> n[i];
    while (n[i]--) {
      long long l, r;
      cin >> l >> r;
      split(0, (1LL << 60) - 1, l, r, 60, seg[i]);
    }
    seg[i] = reb(seg[i]);
  }
  set<pair<long long, long long> > s;
  for (auto S1 : seg[0])
    for (auto s2 : seg[1]) {
      auto s1 = S1;
      int mx = max(s1.second, s2.second);
      s1.first >>= mx;
      s1.first <<= mx;
      s2.first >>= mx;
      s2.first <<= mx;
      long long xl = s1.first ^ s2.first;
      long long xr = xl + (1LL << mx) - 1;
      auto it = s.lower_bound({xl, -INF});
      if (it != s.begin()) {
        auto it2 = --it;
        if (it2->first <= xl && it2->second >= xr) continue;
      }
      while (true) {
        auto it = s.lower_bound({xl, -INF});
        if (it == s.end()) break;
        if (it->first >= xl && it->second <= xr) {
          s.erase(it);
        } else
          break;
      }
      it = s.lower_bound({xl, -INF});
      if (it != s.end()) {
        if (it->first - 1 <= xr) {
          xr = it->second;
          s.erase(it);
        }
      }
      it = s.lower_bound({xl, -INF});
      if (it != s.begin()) {
        it--;
        if (it->second + 1 >= xl) {
          xl = it->first;
          s.erase(it);
        }
      }
      s.insert({xl, xr});
    }
  long long ans = 0;
  for (auto first : s) {
    ans = add(ans, sum(first.first, first.second));
  }
  cout << ans;
  return 0;
}
