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