#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0;
ll dp[MX][MX];
inline void chmax(ll& a, ll b) { a = max(a, b); }
int main() {
  ll n, q;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < (ll)(n); i++) cin >> a.at(i);
  cin >> q;
  vector<ll> b(q), c(q);
  for (ll i = 0; i < (ll)(q); i++) cin >> b.at(i) >> c.at(i);
  ll cnt = 0;
  for (ll i = 0; i < (ll)(n); i++) cnt += a.at(i);
  vector<ll> set(100005, 0);
  for (ll i = 0; i < (ll)(n); i++) {
    set.at(a.at(i))++;
  }
  for (ll i = 0; i < (ll)(q); i++) {
    ll tmp = set.at(b.at(i));
    set.at(c.at(i)) += tmp;
    cnt += (c.at(i) - b.at(i)) * tmp;
    cout << cnt << endl;
  }
}
