#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N];
void solve_test_case() {
  int n, q, b, c, s = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    for (int i = 0; i < n; ++i) {
      if (a[i] == b) {
        a[i] = c;
      }
      s += a[i];
    }
    cout << s << "\n";
    s = 0;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve_test_case();
  }
}
