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