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