#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  int64_t S;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> B(Q);
  vector<int64_t> C(Q);
  S = 0LL;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i) >> C.at(i);
  }
  for (int i = 0; i < Q; i++) {
    replace(A.begin(), A.end(), B.at(i), C.at(i));
    for (int i = 0; i < N; i++) {
      S = S + A.at(i);
    }
    cout << S << endl;
    S = 0;
  }
}
