#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x / GCD(x, y) * y; }
int main() {
  ll n;
  cin >> n;
  ll a[100005], b[100005], c[100005];
  ll sum[100005];
  map<ll, ll> m;
  for (int i = (0); i < (n); i++) {
    cin >> a[i];
    sum[0] += a[i];
    m[a[i]]++;
  }
  ll q;
  cin >> q;
  for (int i = (1); i < (q + 1); i++) cin >> b[i] >> c[i];
  for (int i = (1); i < (q + 1); i++) {
    ll d = c[i] - b[i];
    sum[i] = sum[i - 1] + m[b[i]] * d;
    m[c[i]] += m[b[i]];
  }
  for (int i = (1); i < (q + 1); i++) cout << sum[i] << endl;
  return 0;
}
