#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int brr[100001] = {};
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    brr[arr[i]]++;
  }
  int cnt;
  cin >> cnt;
  int total = sum;
  for (int i = 0; i < cnt; i++) {
    int a, b;
    cin >> a >> b;
    if (brr[a] > 0) {
      int temp = brr[a];
      brr[a] = 0;
      brr[b] += temp;
      total += temp * (b - a);
    }
    cout << total << endl;
  }
}
