using namespace std;
#define _GLIBCXX_DEBUG
// 省略
#define ll long long
#define ld long double
#define Vi vector<int>
#define Vl vector<ll>
// for
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Repp(i, a, b) for (int i = a; i <= (int)(b); i++)
#define Repm(i, a, b) for (int i = a; i <= (int)(b); i—-)
// 入力
#define ini(x) int x; cin >> x;
#define inl(x) ll x; cin >> x;
#define ind(x) double x; cin >> x;
#define inc(x) char x; cin >> x;
#define ins(x) string x; cin >> x;
// 出力
#define co(x) cout << x;
#define ce cout << endl;
#define cs cout << “ “;
#define keta(x) cout << fixed << setprecision(x);
// 配列
#define Sort(x) sort(x.begin(), x.end()); // 小順
#define Rev(x) reverse(x.begin(), x.end());

int main() {
  ini(N)
  Vi As(200000, 0);
  rep(i, N){
    ini(A) As[A]++; 
  }
  
  ll ans = 0;
  rep(i, 200000){
    ans += i*As[i];
  }
    
  ini(Q) 
  rep(i, Q){
    ini(B) ini(C)
    int keep;
    keep = As[B]; As[B] = 0;
    ans -= keep*B;
    As[C] += keep;
    ans += keep*C;
    co(ans) ce
  }
}