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 MOD = 998244353;
const int BITS = 60;
struct tree_node {
  int child[2] = {-1, -1};
  bool full = false;
};
struct tree {
  vector<tree_node> nodes = {tree_node()};
  int get_or_create_node(int &node) {
    int answer = node;
    if (node < 0) {
      answer = node = nodes.size();
      nodes.emplace_back();
    }
    return answer;
  }
  void recursive_add(int node, int bit, long long prefix, long long start,
                     long long end) {
    long long after = prefix + (1LL << bit);
    if (start <= prefix && after <= end) {
      nodes[node].full = true;
      return;
    }
    if (bit <= 0) return;
    long long mid = (prefix + after) / 2;
    if (start < mid)
      recursive_add(get_or_create_node(nodes[node].child[0]), bit - 1, prefix,
                    start, end);
    if (end > mid)
      recursive_add(get_or_create_node(nodes[node].child[1]), bit - 1, mid,
                    start, end);
  }
  void add_range(long long L, long long R) { recursive_add(0, BITS, 0, L, R); }
};
tree a_tree, b_tree;
vector<pair<int, int>> options[BITS + 1];
long long dfs_sum(int bit, long long prefix) {
  for (pair<int, int> &p : options[bit])
    if (a_tree.nodes[p.first].full || b_tree.nodes[p.second].full) {
      long long count = 1LL << bit;
      long long prefix_sum = (prefix % MOD) * (count % MOD);
      long long bit_sum = (count / 2 % MOD) * ((count - 1) % MOD);
      return (prefix_sum + bit_sum) % MOD;
    }
  if (bit <= 0) return 0;
  long long sum = 0;
  for (int next = 0; next < 2; next++) {
    options[bit - 1].clear();
    for (pair<int, int> &p : options[bit])
      for (int left = 0; left < 2; left++) {
        int right = left ^ next;
        int a_child = a_tree.nodes[p.first].child[left];
        int b_child = b_tree.nodes[p.second].child[right];
        if (a_child >= 0 && b_child >= 0)
          options[bit - 1].emplace_back(a_child, b_child);
      }
    if (!options[bit - 1].empty()) {
      long long add = (long long)next << (bit - 1);
      sum = (sum + dfs_sum(bit - 1, prefix + add)) % MOD;
    }
  }
  return sum;
}
int main() {
  int A, B;
  cin >> A;
  for (int i = 0; i < A; i++) {
    long long L, R;
    cin >> L >> R;
    R++;
    a_tree.add_range(L, R);
  }
  cin >> B;
  for (int i = 0; i < B; i++) {
    long long L, R;
    cin >> L >> R;
    R++;
    b_tree.add_range(L, R);
  }
  options[BITS].emplace_back(0, 0);
  cout << dfs_sum(BITS, 0) << '\n';
}
