#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5 + 1;
const long long INF = 1e10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n, t, q;
  long long sum = 0;
  cin >> n;
  vector<int> cnt(N);
  for (int i = 0; i < n; i++) {
    cin >> t;
    cnt[t]++;
    sum += t;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    t = cnt[b];
    cnt[b] = 0;
    sum -= (t * b);
    sum += (t * c);
    cnt[c] += t;
    cout << sum << '\n';
  }
}
