#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int arr[N];
  int sum = 0;
  int Q;
  int arr_data[Q][2];
  for (int i = 0; i < N; i++) {
    cin >> arr[i];
  }
  cin >> Q;
  for (int m = 0; m < Q; m++) {
    for (int j = 0; j < 2; j++) {
      cin >> arr_data[m][j];
    }
  }
  for (int q = 0; q < Q; q++) {
    sum = 0;
    for (int k = 0; k < N; k++) {
      if (arr[k] == arr_data[q][0]) {
        arr[k] = arr_data[q][1];
      }
      sum += arr[k];
    }
    cout << sum << endl;
  }
  return 0;
}
