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