#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
    int N, M, K;
    vector<int> A, B, C, D;

    cin >> N >> M;
    A.resize(M); B.resize(M);
    rep(i, M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; }

    cin >> K;
    C.resize(K); D.resize(K);
    rep(i, K) { cin >> C[i] >> D[i]; C[i]--; D[i]--; }

    int ans = 0;
    rep(bit, 1 << K) {
        int cnt = 0;
        vector<int> ball(N, 0);
        rep(i, K) {
            if (bit & 1 << i) ball[C[i]]++;
            else ball[D[i]]++;
        }
        rep(i, M) if (ball[A[i]] > 0 && ball[B[i]] > 0) cnt++;
        chmax(ans, cnt);
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ostream &operator<<(ostream &os, const vector<lli> &x){
    os << "{";
    for(int i = 0; i < x.size(); i++){
        if(i < x.size()-1) os << x[i] << ", ";
        else os << x[i];
    }
    os << "}";
    return os;
}

const lli mod = 998244353;
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt< mod >;

int main(void){
    int n;
    cin >> n;
    vector<lli> x(n);
    vector<mint> a(n);
    mint ans = 0;
    
    rep(i, n){
        cin >> x[i];
    }
    
    if(n == 1){
        ans = x[0];
        ans *= x[0];
        cout << ans << endl;
        return 0;
    }
    sort(x.begin(), x.end());
    rep(i, n) a[i] = x[i];
    vector<mint> b(n);
    mint t = 2;
    rep(i, n){
        b[0] += t.pow(i)*a[i];
    }
    for(int i = 1; i < n; i++){
        b[i] = b[i-1]-a[i-1];
        b[i]/=2;
    }
    rep(i, n-1){
        ans += a[i]*b[i+1];
    }
    rep(i, n) ans += a[i]*a[i];
    cout << ans << endl;
    return 0;
}
