#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  int B[Q], C[Q];
  long long int S;
  for (int i = 0; i < Q; i++) {
    int B, C, ans;
    ans = 0;
    cin >> B >> C;
    for (int j = 0; j < N; j++) {
      if (A[j] == B) {
        A[j] = C;
      }
      ans += A[j];
    }
    cout << ans << endl;
  }
}
