#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int f[N];
void solve() {
  int n;
  cin >> n;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
    f[x]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    if (f[x]) {
      sum -= x * 1LL * f[x];
      sum += y * 1LL * f[x];
      f[y] += f[x];
    }
    cout << sum << "\n";
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
