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