#include <bits/stdc++.h>
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6 + 3);
int dir4[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int knight[8][2] = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1},
                    {1, 2}, {-1, 2}, {1, -2}, {-1, -2}};
using namespace std;
void solve() {
  int n;
  cin >> n;
  int cnt[100010] = {0};
  int a[n + 1];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    cnt[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int b, c;
    cin >> b >> c;
    sum -= (b * cnt[b]);
    sum += (cnt[b] * c);
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << "\n";
  }
}
int main() {
  int t = 1;
  int i = 1;
  while (t--) {
    solve();
  }
  return 0;
}
