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