#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> vec;
  vector<char> cvec;
  vector<string> svec;
  int a, b, x[100000], y[100000], z[100000], count = 0;
  string str1[10], str2;
  char c[10];
  cin >> a;
  for (long long i = 1; i <= (long long)(a); i++) cin >> x[i];
  cin >> b;
  for (long long i = 1; i <= (long long)(a); i++) {
    cin >> y[i];
    cin >> z[i];
  }
  int u;
  for (long long u = 1; u <= (long long)(b); u++) {
    for (long long i = 1; i <= (long long)(a); i++)
      if (y[i] == x[i]) x[i] = z[i];
  }
  for (long long i = 1; i <= (long long)(a); i++) count += x[i];
  auto answer = count;
  cout << answer << endl;
  return 0;
}
