#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[i];
  }
  int q;
  cin >> q;
  vector<int> B(q);
  vector<int> C(q);
  for (int i = 0; i < (q); ++i) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < (q); ++i) {
    ll tot = 0;
    for (int j = 0; j < (n); ++j) {
      if (A[j] == B[i]) {
        A[j] = C[i];
      }
    }
    for (int k = 0; k < (n); ++k) {
      tot += A[k];
    }
    cout << tot << endl;
  }
}
