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