#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

const int MX = 100005;
 
int main(){
  ll n;
  cin >> n;
  vector<ll> cnt(MX);
  rep(i,n){
    int a;
    cin >> a;
    cnt[a]++;
  }
  ll tot = 0;
  rep(i,MX)tot += i*cnt[i];
  //変化量で計算
  int q;
  cin >> q;
  rep(i,q){
    int b, c;
    cin >> b >> c;
    tot += (c-b)*cnt[b];
  }
  cout << f(n) << endl;
}