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