#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const long long linf = (long long)inf * (long long)inf;
void solve() {
  int n;
  cin >> n;
  long long h[100001];
  for (long long i = 0; i < (100001); i++) h[i] = 0;
  long long ans = 0;
  for (long long i = 0; i < (n); i++) {
    int a;
    cin >> a;
    ans += a;
    h[a]++;
  }
  int q;
  cin >> q;
  for (long long i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    ans += (c - b) + h[b];
    h[c] += h[b];
    h[b] = 0;
    cout << ans << '\n';
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
}
