#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const double pi = 3.14159265359;
int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long Q;
  cin >> Q;
  vector<long long> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
    }
    long long sum = 0;
    for (int i = 0; i < N; i++) {
      sum += A[i];
    }
    cout << sum << endl;
  }
}
