#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;
int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}};
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w) {
  return (y >= 0 && y < h && x >= 0 && x < w);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  ll n;
  cin >> n;
  vi a(n, 0);
  ll s = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a[t - 1]++;
    s += t;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    s += (c - b) * a[b - 1];
    a[c - 1] += a[b - 1];
    a[b - 1] = 0;
    cout << s << endl;
  }
}
