#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main() {
  cin.tie(0);
  ll n, a[100000], q, b[100000], c[100000], sum = 0, list[100000] = {};
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i - 1];
    sum += a[i - 1];
    list[a[i - 1]]++;
  }
  cin >> q;
  for (ll i = 1; i <= q; i++) {
    cin >> b[i - 1] >> c[i - 1];
  }
  for (ll i = 1; i <= q; i++) {
    sum += list[b[i - 1]] * (c[i - 1] - b[i - 1]);
    cout << sum << endl;
    list[c[i - 1]] += list[b[i - 1]];
    list[b[i - 1]] = 0;
  }
  return 0;
}
