#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main(void) {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  int b, c;
  Graph G(Q);
  for (int i = 0; i < Q; i++) {
    cin >> b >> c;
    G[b].push_back(c);
  }
  for (int i = 0; i < (int)G.size(); i++) {
    for (int j = 0; j < N; j++) {
      if (G[i][G[i].size() - 1] == A[j]) {
        A[j] = G[i][G[i].size() - 1];
      }
    }
  }
  int result;
  for (int i = 0; i < N; i++) {
    result += A[i];
  }
  cout << result << endl;
  return 0;
}
