#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const long long mod = 1e9 + 7;
const int X = 200005;
void flash() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(10);
}
struct Value {
  int value = -1;
};
void solve();
int32_t main() {
  flash();
  int t;
  t = 1;
  for (int zz = 0; zz < t; zz++) {
    solve();
  }
  return 0;
}
void solve() {
  map<int, int> mp;
  int n;
  cin >> n;
  int x;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mp[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    if (mp[b] != 0) {
      sum -= b * mp[b];
      sum += c * mp[b];
      mp[c] += mp[b];
      mp[b] = 0;
    }
    cout << sum << "\n";
  }
  return;
}
