#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[n], q, b[q], c[q];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++)
      if (a[j] == b[i]) a[j] == c[i];
    int all = 0;
    for (int j = 0; j < n; j++) all += a[j];
    cout << all;
  }
  return 0;
}
