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