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