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