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