#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
  int n, sum;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    sum = 0;
    cin >> b;
    cin >> c;
    for (int j = 0; j < n; j++) {
      if (b == v[j]) {
        v[j] = c;
      }
    }
    for (int i = 0; i < n; i++) {
      sum = sum + v[i];
    }
    cout << sum << endl;
  }
  return 0;
}
