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