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