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