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 {
  long long prefix;
  int child[2] = {-1, -1};
  bool full = false;
};
struct tree {
  vector<tree_node> nodes = {tree_node()};
  vector<int> levels[BITS + 1];
  int get_or_create_node(int bit, long long prefix, int &node) {
    int answer = node;
    if (node < 0) {
      answer = node = nodes.size();
      levels[bit].push_back(node);
      nodes.emplace_back();
      nodes.back().prefix = prefix;
    }
    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) {
      int left = get_or_create_node(bit - 1, prefix, nodes[node].child[0]);
      recursive_add(left, bit - 1, prefix, start, end);
    }
    if (end > mid) {
      int right = get_or_create_node(bit - 1, mid, nodes[node].child[1]);
      recursive_add(right, bit - 1, mid, start, end);
    }
  }
  void add_range(long long L, long long R) { recursive_add(0, BITS, 0, L, R); }
  void add_single(int bit, long long prefix) {
    recursive_add(0, BITS, 0, prefix, prefix + (1LL << bit));
  }
  long long dfs_sum(int node, int bit, long long prefix) {
    if (nodes[node].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;
    if (nodes[node].child[0] >= 0)
      sum += dfs_sum(nodes[node].child[0], bit - 1, prefix);
    if (nodes[node].child[1] >= 0)
      sum +=
          dfs_sum(nodes[node].child[1], bit - 1, prefix + (1LL << (bit - 1)));
    return sum % MOD;
  }
};
int main() {
  int A, B;
  tree a_tree, b_tree;
  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);
  }
  tree xor_tree;
  for (int bit = 0; bit < BITS; bit++)
    for (int a_node : a_tree.levels[bit])
      for (int b_node : b_tree.levels[bit])
        if (a_tree.nodes[a_node].full || b_tree.nodes[b_node].full)
          xor_tree.add_single(
              bit, a_tree.nodes[a_node].prefix ^ b_tree.nodes[b_node].prefix);
  cerr << xor_tree.nodes.size() << " nodes" << endl;
  cout << xor_tree.dfs_sum(0, BITS, 0) << '\n';
}
