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