#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long m, b, c;
  cin >> m;
  while (m--) {
    cin >> b >> c;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
      sum = sum + a[i];
    }
    cout << sum << "\n";
  }
}
