#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(NULL);
  int n, x, q;
  long long int sum = 0;
  map<int, int> cnt;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cnt[x]++;
    sum += x;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    x = cnt[a];
    sum -= x * a;
    sum += x * b;
    cnt[a] -= x;
    cnt[b] += x;
    cout << sum << "\n";
  }
  return 0;
}
