#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > que;
priority_queue<long long> Que;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int n;
vector<int> a;
long long calc(int b, int c) {
  long long ret = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == b) a[i] = c;
    ret += a[i];
  }
  return ret;
}
void solve() {
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    cout << calc(b, c) << endl;
  }
}
int main() {
  solve();
  return 0;
}
