#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int cnt[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum = sum - cnt[x] * x + cnt[x] * y;
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout << sum << '\n';
  }
}
