#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && (c != '-')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * f;
}
const int N = 1e4 + 10;
int n, m;
pair<long long, long long> a[N], b[N];
inline void rd(int &n, pair<long long, long long> *a) {
  int cnt = read();
  vector<pair<long long, long long> > v(cnt);
  for (register int i = (0); i < (cnt); i++)
    v[i].first = read(), v[i].second = read();
  sort((v).begin(), (v).end());
  long long l = v[0].first, r = v[0].second;
  for (register int i = (1); i < (cnt); i++)
    if (v[i].first <= r)
      r = max(r, v[i].second);
    else
      a[++n] = make_pair(l, r), l = v[i].first, r = v[i].second;
  a[++n] = make_pair(l, r);
}
vector<pair<long long, long long> > A, B, C;
inline void Insert(int len, long long l, long long r, long long ql,
                   long long qr) {
  if (l >= ql && r <= qr) return C.push_back(make_pair(len, l)), void(0);
  long long mid = l + r >> 1;
  if (ql <= mid) Insert(len - 1, l, mid, ql, qr);
  if (qr > mid) Insert(len - 1, mid + 1, r, ql, qr);
}
const int maxn = 1e6 + 3;
struct Hash_Table {
  int cnt, now_id, first[maxn], id[maxn], last[maxn];
  long long val1[maxn], val2[maxn];
  inline void init() { cnt = 0, ++now_id; }
  inline void insert(long long s, int v) {
    int S = s % maxn;
    if (id[S] != now_id) id[S] = now_id, first[S] = 0;
    for (int i = first[S]; i; i = last[i])
      if (val1[i] == s) return val2[i] += v, void(0);
    ++cnt, last[cnt] = first[S], first[S] = cnt, val1[cnt] = s, val2[cnt] = v;
  }
} h;
const int mod = 998244353, inv = (mod + 1) >> 1;
inline long long calc(long long l, long long r) {
  return (l + r) % mod * ((r - l + 1) % mod) % mod;
}
int main() {
  rd(n, a), rd(m, b);
  vector<pair<long long, long long> > mg;
  for (register int i = (1); i <= (n); i++)
    for (register int j = (1); j <= (m); j++) {
      C.clear();
      Insert(60, 0, (1ll << 60) - 1, a[i].first, a[i].second);
      A = C;
      C.clear();
      Insert(60, 0, (1ll << 60) - 1, b[j].first, b[j].second);
      B = C;
      h.init();
      for (auto x : A)
        for (auto y : B) {
          int d = max(x.first, y.first);
          long long l = ((x.second ^ y.second) >> d) << d;
          h.insert(l, 1), h.insert(l + (1ll << d), -1);
        }
      for (register int k = (1); k <= (h.cnt); k++)
        mg.push_back(make_pair(h.val1[k], h.val2[k]));
    }
  sort((mg).begin(), (mg).end());
  long long pre = 0, ans = 0, r = 0;
  for (auto i : mg) {
    if (pre > 0) ans = (ans + calc(r, i.first - 1)) % mod;
    pre += i.second, r = i.first;
  }
  printf("%d\n", ans * inv % mod);
}
