#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll n, k = 0;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    k += a[i];
  }
  ll q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    ll b, c;
    cin >> b >> c;
    ll ans = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b) {
        a[j] = c;
        ans++;
      }
    }
    k += (c - b) * ans;
    cout << k << endl;
  }
}
