#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<int> A;
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    A.push_back(temp);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    int sum = 0;
    for (int j = 0; j < N; j++) {
      if (A[j] == B) A[j] = C;
      sum += A[j];
    }
    cout << sum << endl;
  }
}
