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