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