#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> avc(100001, 0);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++avc[a];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    --avc[b];
    ++avc[c];
  }
  long long ret = 0;
  for (int i = 0; i <= 100001; ++i) {
    ret += (long long)i * (long long)avc[i];
  }
  cout << ret << endl;
  return 0;
}
