#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, m, k, l, r, x, y, q, res, ans, t;
string s1, s2;
int count = 0;
void solve() {
  cin >> n;
  int a[n];
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int a1, b;
    cin >> a1 >> b;
    int i = 0;
    int sum = 0;
    while (i < n) {
      if (a[i] == a1) {
        a[i] = b;
      }
      sum += a[i];
      i++;
    }
    cout << sum << endl;
  }
}
int main() {
  solve();
  return 0;
}
