#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int soma = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    soma = 0;
    int b, c;
    cin >> b >> c;
    vector<int>::iterator it = find(v.begin(), v.end(), b);
    if (it != v.end()) {
      for (int i = 0; i < n; ++i) {
        if (v[i] == b) {
          v[i] = c;
        }
        soma += v[i];
      }
      cout << soma << endl;
    } else {
      for (int i = 0; i < n; ++i) {
        soma += v[i];
      }
      cout << soma << endl;
    }
  }
  return 0;
}
