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