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