#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MX = 1e18;
const long double PI = acos(-1);
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  ll ans = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    ans += a[i];
  }
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    for (int j = 0; j < (n); ++j) {
      if (a[j] == b) {
        a[j] = c;
        ans += (c - b);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
