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