#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, B, C, Sum = 0;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A.at(i);
  cin >> Q;
  for (int i = 0; i < (int)(Q); i++) {
    cin >> B >> C;
    for (int j = 0; j < (int)(N); j++) {
      if (A.at(j) == B) A.at(j) = C;
      Sum += A.at(j);
    }
    cout << Sum << endl;
    Sum = 0;
  }
}
