#include <bits/stdc++.h>
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
int n;
int a[N];
int q;
int b, c;
map<int, int> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> b >> c;
    int cnt = mp[b];
    sum = sum - cnt * b + cnt * c;
    mp[b] = 0;
    mp[c] += cnt;
    cout << sum << endl;
  }
  return 0;
}
