#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> q;
  int b, c;
  for (int i = 0; i < q; ++i) {
    int 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;
}
