#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    for (int n = 0; n < N; n++) {
      auto itr = find(A.begin(), A.end(), B);
      if (itr != A.end()) {
        *itr = C;
      } else {
        break;
      }
    }
    cout << accumulate(A.begin(), A.end(), 0LL) << endl;
  }
}
