#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int M = 1e5 + 5;
const int mod = 998244353;
const int inv = 499122177;
inline long long read() {
  long long x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x;
}
long long lim = (1LL << 60) - 1;
int na, nb, rt, cnt;
int ch[M][2];
struct node {
  long long l, r;
  node() {}
  node(long long L, long long R) { l = L, r = R; }
} a[N], b[N];
vector<node> va[N], vb[N], ans;
int nd() {
  ch[++cnt][0] = 0, ch[cnt][1] = 0;
  return cnt;
}
void gnd1(int &o, long long l, long long r, long long x, long long y, int d) {
  if (!o) o = nd(), va[d].push_back(node(l, r));
  if (x <= l && r <= y) return;
  long long mid = (l + r) >> 1;
  if (x <= mid) gnd1(ch[o][0], l, mid, x, y, d + 1);
  if (mid < y) gnd1(ch[o][1], mid + 1, r, x, y, d + 1);
}
void gnd2(long long l, long long r, long long x, long long y, int d) {
  if (x <= l && r <= y) {
    vb[d].push_back(node(l, r));
    return;
  }
  long long mid = (l + r) >> 1;
  if (x <= mid) gnd2(l, mid, x, y, d + 1);
  if (mid < y) gnd2(mid + 1, r, x, y, d + 1);
}
void solve() {
  rt = cnt = 0;
  for (register int i = 0; i <= 60; i++) va[i].clear(), vb[i].clear();
  for (register int i = 1; i <= na; i++) gnd1(rt, 0, lim, a[i].l, a[i].r, 0);
  for (register int i = 1; i <= nb; i++) gnd2(0, lim, b[i].l, b[i].r, 0);
  for (register int i = 0; i <= 60; i++) {
    for (vector<node>::iterator it1 = va[i].begin(); it1 != va[i].end();
         it1++) {
      for (vector<node>::iterator it2 = vb[i].begin(); it2 != vb[i].end();
           it2++) {
        long long low = it2->l ^ it2->r;
        ans.push_back(
            node((it2->l ^ it1->l) & (~low), (it2->l ^ it1->l) | low));
      }
    }
  }
}
bool operator<(node a, node b) { return a.l < b.l; }
long long cal(long long l, long long r) {
  l %= mod, r %= mod;
  return (r - l + mod + 1) % mod * (l + r) % mod * inv % mod;
}
int main() {
  na = read();
  for (register int i = 1; i <= na; i++) a[i].l = read(), a[i].r = read();
  nb = read();
  for (register int i = 1; i <= nb; i++) b[i].l = read(), b[i].r = read();
  solve();
  swap(a, b), swap(na, nb), solve();
  sort(ans.begin(), ans.end());
  if (!ans.size()) return puts("0"), 0;
  long long L = ans.begin()->l, R = ans.begin()->r, anss = 0;
  for (vector<node>::iterator it = ans.begin() + 1; it != ans.end(); it++) {
    if (it->l <= R + 1)
      R = max(R, it->r);
    else
      (anss += cal(L, R)) %= mod, L = it->l, R = it->r;
  }
  anss = (anss + cal(L, R)) % mod;
  printf("%lld", anss);
}
