#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  ;
  int n;
  cin >> n;
  map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    int cnt = mp[x];
    sum -= (cnt * x);
    mp[x] = 0;
    sum += (cnt * y);
    mp[y] += cnt;
    cout << sum << '\n';
  }
}
