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