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