#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1 << 29;
using Graph = vector<vector<int>>;
int main() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int q;
  cin >> q;
  vector<long long int> b(q);
  vector<long long int> c(q);
  for (long long int i = 0; i < q; i++) cin >> b[i] >> c[i];
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    sum += a[i];
  }
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
        sum += (c[i] - b[i]);
      }
    }
    cout << sum << endl;
  }
}
