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