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