#include <bits/stdc++.h>
using namespace std;
int s[100004];
int main() {
  int t, ans = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> s[i];
    ans += s[i];
  }
  int r;
  cin >> r;
  for (int i = 0; i < r; i++) {
    int a, b;
    cin >> a >> b;
    int q = b - a;
    for (int j = 0; j < t; j++)
      if (s[j] == a) {
        ans += q;
        s[j] = b;
      }
    cout << ans << endl;
  }
  return 0;
}
