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