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