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