#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    while (find(v.begin(), v.end(), b) != v.end()) {
      auto it = find(v.begin(), v.end(), b);
      v[it - v.begin()] = c;
      long long diff = c - b;
      sum += diff;
    }
    cout << sum << "\n";
  }
}
