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