#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
const long long MAXN = 100005;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  ;
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  long long cur = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    cur += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long del = c - b;
    long long cnt = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
        cnt++;
      }
    }
    cur += cnt * del;
    cout << cur << '\n';
  }
  return 0;
}
