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