#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k, s = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  cin >> k;
  vector<pair<int, int>> m;
  for (int i = 0; i < k; ++i) {
    int c, b;
    cin >> c >> b;
    m.push_back(make_pair(c, b));
  }
  for (int j = 0; j < k; ++j) {
    s = 0;
    int i = 0;
    while (i < n) {
      if (a[i] == m[j].first) {
        a[i] = m[j].second;
      }
      s = s + a[i];
      ++i;
    }
    cout << s << "\n";
  }
  return 0;
}
