#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, q, b, c;
  vector<int> v;
  cin >> n;
  for (long long int i = (0); i <= (n - 1); i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  cin >> q;
  while (q--) {
    int sum = 0;
    cin >> b >> c;
    for (long long int i = (0); i <= (n - 1); i++) {
      if (v[i] == b) v[i] = c;
      sum += v[i];
    }
    cout << sum << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  clock_t time_p = clock();
  int test;
  test = 1;
  while (test--) {
    solve();
  }
  cerr << "\n\nTime Taken : " << fixed << setprecision(5)
       << (float)(clock() - time_p) / CLOCKS_PER_SEC << '\n';
  return 0;
}
