#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int a[maxn];
int main() {
  int n, q, x, y;
  long long sum = 0;
  cin >> n;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> x >> y;
    int num = mp[x];
    sum -= num * x;
    mp[x] = 0;
    sum += num * y;
    mp[y] += num;
    cout << sum << endl;
  }
  return 0;
}
