#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, q, sum = 0;
  map<long long, long long> map;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    sum += a;
    if (map.count(a))
      map[a]++;
    else
      map[a] = 1;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long b, c, match;
    cin >> b >> c;
    if (map.count(b)) {
      match = map.at(b);
    } else {
      cout << sum << endl;
      continue;
    }
    sum = sum - (match * b) + (match * c);
    if (map.count(c))
      map.at(c) += match;
    else
      map[c] = match;
    cout << sum << endl;
  }
  return 0;
}
