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