#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using garph = vector<vector<ll>>;
const long long inf = 2147483647;
const ll INF = 9223372036854775807;
signed main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  long long q;
  cin >> q;
  vector<long long> m(100001);
  vector<long long> p(100001);
  for (ll i = 0; i < n; i++) {
    m[a[i]] += a[i];
    p[a[i]]++;
  }
  for (ll i = 0; i < q; i++) {
    long long b, c;
    cin >> b >> c;
    m[c] += p[b] * c;
    p[c] += p[b];
    m[b] = p[b] = 0;
    cout << accumulate((m).begin(), (m).end(), 0LL) << "\n";
  }
  return 0;
}
