#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll n, q;
vector<long long> a, b, c;
void input() {
  cin >> n;
  for (ll i = 0; i < (ll)n; i++) {
    ll A;
    cin >> A;
    a.push_back(A);
  }
  cin >> q;
  for (ll i = 0; i < (ll)q; i++) {
    ll B, C;
    cin >> B >> C;
    b.push_back(B);
    c.push_back(C);
  }
}
void solve() {
  ll d[100010];
  ll sum = 0;
  for (ll i = 0; i < (ll)n; i++) {
    sum += a[i];
  }
  for (ll i = 0; i < (ll)n; i++) {
    d[a[i]]++;
  }
  for (ll i = 0; i < (ll)q; i++) {
    ll x = d[b[i]];
    sum += x * (c[i] - b[i]);
    d[c[i]] += x;
    d[b[i]] -= x;
    cout << sum << endl;
  }
}
int main() {
  input();
  solve();
  return 0;
}
