#include <bits/stdc++.h>
const int SIZE = 1000005;
using namespace std;
int n, q, b, c;
int a[1005];
int ans;
int main() {
  cin >> n;
  ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ans += a[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    int j = c - b;
    for (int i = 0; i < n; i++)
      if (a[i] == b) {
        ans += j;
        a[i] = c;
      }
    cout << ans << endl;
  }
  return 0;
}
