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