#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
const int maxN = 5e3;
int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        sum += c - b;
        a[i] = c;
      }
    }
    cout << sum << "\n";
  }
}
