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 long long inf = 1ll << 60;
const int Mod = 998244353;
const int inv2 = (Mod + 1) / 2;
struct node {
  static node *null;
  node *c[2];
  bool real;
  node() {
    real = 0;
    c[0] = c[1] = null;
  }
  void ins(long long s, long long t, long long l = 0, long long r = inf - 1) {
    if (s <= l && r <= t) return real = 1, void();
    if (s <= (l + r >> 1)) {
      if (c[0] == null) c[0] = new node;
      c[0]->ins(s, t, l, (l + r >> 1));
    }
    if (t > (l + r >> 1)) {
      if (c[1] == null) c[1] = new node;
      c[1]->ins(s, t, (l + r >> 1) + 1, r);
    }
  }
  void init() {
    int n;
    long long l, r;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> l >> r;
      ins(l, r);
    }
  }
};
typedef pair<node *, node *> pr;
vector<pr> q[70];
long long work(long long pre, long long d) {
  for (pr pt : q[d])
    if (pt.first->real || pt.second->real)
      return (pre % Mod + ((1ll << d) - 1) % Mod * inv2 % Mod) % Mod *
             ((1ll << d) % Mod) % Mod;
  long long res = 0;
  for (long long x = 0; x < 2; x++) {
    q[d - 1].clear();
    for (pr pt : q[d])
      for (int y = 0; y < 2; y++)
        if (pt.first->c[y] != node::null && pt.second->c[x ^ y] != node::null)
          q[d - 1].push_back(pr(pt.first->c[y], pt.second->c[x ^ y]));
    if (q[d - 1].size()) res = (res + work(pre | (x << (d - 1)), d - 1)) % Mod;
  }
  return res;
}
node *node::null = new node;
node *ta = new node;
node *tb = new node;
int main() {
  ios::sync_with_stdio(false);
  ta->init();
  tb->init();
  q[60].push_back(pr(ta, tb));
  cout << (work(0, 60) % Mod + Mod) % Mod << endl;
  return 0;
}
