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