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