#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
bool comp(pair<long long, long long>& a, pair<long long, long long>& b) {
  if (a.second == b.second)
    return a.first > b.first;
  else
    return b.second < a.second;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, q, b, c;
  cin >> n;
  long long a[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    long long sum = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
      sum += a[i];
    }
    cout << sum << endl;
  }
  return 0;
}
