#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a.at(i);
  cin >> q;
  vector<pair<int, int>> bc;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    pair<int, int> p(b, c);
    bc.push_back(p);
  }
  for (int i = 0; i < (q); ++i) {
    int b = bc.at(i).first;
    int c = bc.at(i).second;
    ll ans = 0;
    for (int j = 0; j < (n); ++j) {
      if (a.at(j) == b) a.at(j) = c;
      ans += a.at(j);
    }
    cout << ans << endl;
  }
}
