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