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