#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long N;
  cin >> N;
  long A[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  long Q;
  cin >> Q;
  long B[Q], C[Q];
  long long ans = 0;
  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];
      }
      ans = ans + A[j];
    }
    cout << ans << "\n";
    ans = 0;
  }
}
