#include <bits/stdc++.h>
using namespace std;
int replace(vector<int>& a, int b, int c) {
  int sum = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    if (a[i] == b) a[i] = c;
    sum += a[i];
  }
  return sum;
}
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  vector<int> sum(q);
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum[i] = replace(a, b, c);
  }
  for (int i = 0; i < q; i++) {
    cout << sum[i] << endl;
  }
  return 0;
}
