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