#include <bits/stdc++.h>
using namespace std;
const int mxN = 2e5;
int a[mxN];
int sum(vector<int> v) {
  int s = 0;
  for (int i = 0; i < v.size(); ++i) {
    s += v[i];
  }
  return s;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &x : v) cin >> x;
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; ++i) {
      if (v[i] == a) v[i] = b;
    }
    cout << sum(v) << "\n";
  }
  return 0;
}
