#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using d = double;
int main() {
  int N;
  cin >> N;
  ll M;
  vector<int> X(100005, 0);
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    int a;
    cin >> a;
    M += a;
    X.at(i)++;
  }
  int Q;
  cin >> Q;
  vector<int> B(100005);
  vector<int> D(100005);
  for (int i = 0, i_len = (Q); i < i_len; ++i) {
    int b, c;
    cin >> b >> c;
    M += X.at(b) * (c - b);
    cout << M << endl;
    int v = X.at(c);
    X.at(c) += X.at(b);
    X.at(b) -= v;
  }
}
