#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int a[100], b[100];
char str[100];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  ;
  long long int n;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long int t;
  cin >> t;
  while (t--) {
    long long int ans = 0;
    long long int b, c;
    cin >> b >> c;
    for (long long int i = 1; i <= n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
      ans += a[i];
    }
    cout << ans << endl;
    ;
  }
}
