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