#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, p[100005], sum = 0, s[100005], b, c, tmp;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    sum += p[i];
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    if (i == 0)
      s[i] = sum;
    else
      s[i] = s[i - 1];
    int cnt = 0;
    cin >> b >> c;
    cnt = count(p, p + n, b);
    for (int j = 0; j < cnt; j++) {
      tmp = distance(p, find(p, p + n, b));
      p[tmp] = c;
      s[i] = s[i] - b + c;
    }
  }
  for (int i = 0; i < k; i++) cout << s[i] << endl;
}
