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