#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < (N); ++i) {
    cin >> A.at(i);
  }
  int Q;
  cin >> Q;
  vector<vector<int>> bc(Q, vector<int>(2));
  for (int i = 0; i < (Q); ++i) {
    cin >> bc.at(i).at(0) >> bc.at(i).at(1);
  }
  for (int i = 0; i < (Q); ++i) {
    ll sum = 0;
    for (int j = 0; j < (N); ++j) {
      if (A.at(j) == bc.at(i).at(0)) {
        A.at(j) = bc.at(i).at(1);
      }
      sum += A.at(j);
    }
    cout << sum << endl;
  }
}
