#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, q, b, c;
  vector<ll> sum, list(100010);
  sum[0] = 0;
  cin >> n;
  for (ll i = 1; i <= n; i++) {
    cin >> a;
    sum[0] += a;
    list[a]++;
  }
  cin >> q;
  sum[1] = sum[0];
  for (ll i = 1; i <= q; i++) {
    cin >> b >> c;
    sum[i] += list[b] * (c - b);
    list[c] += list[b];
    list[b] = 0;
  }
  for (ll i = 1; i <= q; i++) cout << sum[i] << endl;
  return 0;
}
