#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main() {
  int n, q;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  vector<int> B(q);
  vector<int> C(q);
  for (int i = 0; i < q; i++) {
    cin >> B[i] >> C[i];
  }
  vector<int> sum(q);
  for (int j = 0; j < q; j++) {
    for (int i = 0; i < n; i++) {
      if (A[i] == B[j]) {
        A[i] = C[j];
      }
      sum[j] += A[i];
    }
    cout << sum[j] << endl;
  }
  for (int i = 0; i < n; i++) {
  }
  return 0;
}
