#include <bits/stdc++.h>
using namespace std;
long long a[800001], b[500009], lastcall[800000], value[500000];
string s;
vector<long long> v;
map<long long, long long> mp;
int main() {
  ios_base::sync_with_stdio(false);
  long long j = 1, n, m, k, kk = 1, m1 = 0, a1 = 8, grtr = 0, a2 = 20, l, t, ds,
            r, mx = 0, cnt = 0, mn = INT_MAX, h = 0, mod = 1e9 + 7, i;
  char ch;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    cnt += a[i];
    mp[a[i]]++;
  }
  cin >> m;
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    cnt += mp[j] * k - mp[j] * j;
    mp[k] += mp[j];
    cout << cnt << endl;
  }
  return 0;
}
