#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int b, c;
    cin >> b >> c;
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (arr[j] == b) arr[j] = c;
      sum += arr[j];
    }
    cout << sum;
  }
  return 0;
}
