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