#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr};
use itertools::Itertools;
use proconio::{input, marker::Usize1};

fn main() {
    input! {
        p: usize,
        q: usize,
        r: usize
    };
    println!("{}", vec![p + q, q + r, r + p].into_iter().min().unwrap());
}


var arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var max = 0;
arr.forEach {
  if( max < $0 ) {
    ( max = $0 )
  }
}

for var i = 0; i < 3; i += 1 {
    if( max == arr[i] ) {
		arr.removeAtIndex(i)
      	break
    }
}

print( arr[0] + arr[1] )


/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
    // lastIndex(where:)
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
      	for i in stride(from: count - 1, through: 0, by: -1) {
          	if predicate(self[i]) {
              	return i
            }
        }
      	return nil
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
    // max()
    func max() -> Element? {
        guard self.count > 0 else { return nil }
        return self.reduce(self.first!) { return Swift.max($0, $1) }
    }
}
extension String {
    // Sequence#enumerated()
  	// public func enumerate<Seq : SequenceType>(base: Seq) -> EnumerateSequence<Seq>
    func enumerated() -> EnumerateSequence<[Character]> {
        return Array(self.characters).enumerate()
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}

/// end

let input = readLine()!.split(separator: " ").map { Int($0)! }
let P = input[0]
let Q = input[1]
let R = input[2]

print(min(P + Q, Q + R, R + P))


let inp = readLine()!.split(separator: " ").map { Int($0)! }

let p = inp[0]
let q = inp[1]
let r = inp[2]

print(min(min(p + r, p + q), r + q))


let tmp = readLine()!.characters.split(" ").map{Int(String($0))!}
print((0..<2).reduce(0){$0 + tmp[$1]})


import Foundation

let number = Int(readLine()!)!

//標準入力二行目以降
var weights = [Int]()
let input_line = readLine()!

for i in 0..<number {
    let splits = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	weights.append(Int(splits[i])!)
}

let sumOfWeights = weights.reduce(0, combine: { $0 + $1 }) //重しの総和
var position = 1
var lhsWeight = weights[position - 1]

while sumOfWeights / 2 > lhsWeight {
    position += 1
    lhsWeight += weights[position - 1]
}

if abs(sumOfWeights - (lhsWeight * 2)) <= abs(sumOfWeights - ((lhsWeight - weights[position - 1]) * 2)) {
  print(abs(sumOfWeights - (lhsWeight * 2)))
} else {
  print(abs(sumOfWeights - ((lhsWeight - weights[position - 1]) * 2)))
}


import Foundation

let input_line = readLine()!

let split = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
let P = Int(split[0])!
let Q = Int(split[1])!
let R = Int(split[1])!

let value1 = P + Q
let value2 = P + R
let value3 = Q + R

if value1 <= value2 && value1 <= value3 {
    print(value1)
} else if value2 <= value3 {
    print(value2)
} else {
    print(value3)
}


import * as fs from 'fs';

// a→b b→c c→a
//in
// 6 2 2
//out
// 5
const main = (inp: string) => {

    const [a, b, c]: number[] = inp.split(' ').map(Number);
    const route1: number = a + b;
    const route2: number = b + c;
    const route3: number = c + a;

    console.log(Math.min(route1, route2, route3));
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());


{
  const main = (input: string) => {
    const read = reader(input)
    const [p, q, r] = read.ns()

    console.log(Math.min(p + q, q + r, r + p))
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);
const nin=()=>{const r = input[0];input.shift();return Number(r);}
const sin=()=>{const r = input[0];input.shift();return String(r);}
const out = (...a) => {console.log(...a);}
const min = (...a) => {return Math.min(...a);}
const rep = (n, callback) => {for(let i = 0;i < n; i++){callback();}}
const main = () => {
  let [p, q, r] = [nin(),nin(),nin()];
  out(min(p + q, q + r, r + p));
}
main();


const input = require('fs').readFileSync('/dev/stdin', 'utf8').slice(' ')

console.log(Math.min(input[0]+input[1], input[0]+input[2], input[2]+input[1]))


def main():
    n, *i = map(int, open(0).read().split())
    a = i[:n]
    _ = i[n]
    s = sum(a)

    m = [0] * (10 ** 5 + 1)
    for x in a:
        m[x] += 1

    ans = []
    for b, c in zip(*[iter(i[n + 1:])] * 2):
        m[c] += m[b]
        s += (c - b) * m[b]
        m[b] = 0
        ans.append(s)

    print("\n".join(map(str, ans)))

if __name__ == '__main__':
    main()


# D - Replacing
def main():
    N, *X = map(int, open(0).read().split())
    A, BC = X[:N], X[N + 1 :]
    cnt = [0] * (10 ** 5 + 1)
    for a in A:
        cnt[a] += 1
    total = sum(A)
    res = []
    for b, c in zip(*[iter(BC)] * 2):
        total += (c - b) * cnt[b]
        res.append(total)
        cnt[c] += cnt[b]
        cnt[b] = 0
    print("\n".join(map(str, res)))

if __name__ == "__main__":
    main()


n=int(input())
dict={}
a=list(map(int,input().split()))
for i in a:
  if i not in dict:
    dict[i]=1
  else:
    dict[i]+=1
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  ans=0
  if c in dict and b in dict:
    dict[c]+=dict[b]
  elif c not in dict and b in dict:
    dict[c]=dict[b]
  dict[b]=0
  ans=0
  for j in dict:
    ans+=dict[j]*j
  print(ans)


n=int(input())
dict={}
a=list(map(int,input().split()))
for i in a:
  if i not in dict:
    dict[i]=1
  else:
    dict[i]+=1
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  ans=0
  if c in dict:
    dict[c]+=dict[b]
  else:
    dict[c]=dict[b]
  dict[b]=0
  ans=0
  for j in dict:
    ans+=dict[j]*j
  print(ans)


n=int(input())
dict={}
a=list(map(int,input().split()))
for i in a:
  if i not in dict:
    dict[i]=1
  else:
    dict[i]+=1
q=int(input())
for i in range(q):
  b,c=map(int,input().split())
  ans=0
  for j in dict:
    if j==b:
      ans+=c*dict[b]
    else:
      ans+=j*dict[j]
  if b in dict and c not in dict:
    dict[c]=dict[b]
    dict[b]=0
  elif b in dict and c in dict:
    dict[c]+=dict[b]
    dict[b]=0
  print(ans)


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int n=input.scanInt();
        long arr[]=new long[100001];
        long sum=0;
        for(int i=0;i<n;i++) {
            arr[input.scanInt()]++;
        }
        for(int i=0;i<arr.length;i++) {
            sum+=(i*arr[i]);
        }
        int q=input.scanInt();
        StringBuilder ans=new StringBuilder("");
        for(int query=1;query<=q;query++) {
            int b=input.scanInt();
            int c=input.scanInt();
            long cnt=arr[b];
            sum-=b*arr[b];
            arr[b]=0;
            arr[c]+=cnt;
            sum+=c*cnt;
            ans.append(sum);
            ans.append("\n");
        }
        System.out.println(ans);
    }
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";
    //class  Declaration

    static class pair implements Comparable < pair > {
        int x;
        int y;

        pair(int i, int j) {
            x = i;
            y = j;

        }
        public int compareTo(pair p) {
            if (this.x != p.x) {
                return this.x - p.x;
            } else {
                return this.y - p.y;
            }
        }
        public int hashCode() {
            return (x + " " + y).hashCode();
        }
        public String toString() {
            return x + " " + y;
        }
        public boolean equals(Object o) {
            pair x = (pair) o;
            return (x.x == this.x && x.y == this.y);
        }
    }
    int[] dx = {0,0,1,-1};
    int[] dy = {1,-1,0,0};
    // int[] ddx = {0,0,1,-1,1,-1,1,-1};
    // int[] ddy = {1,-1,0,0,1,-1,-1,1};

int inf = (int) 1e9 + 5;
long mod = (long)1e9 + 7 ;

void solve() throws Exception {
    int n=ni();
    int[] cnt = new int[(int)1e5 + 1];
    long sum = 0;
    for(int i=0;i<n;++i){
        int el = ni();
        cnt[el]++;
        sum = sum+ el ;
    }
    int q=ni();
    while(q-->0){
        int b=ni(), c=ni();
        cnt[c] += cnt[b];
        sum = sum - cnt[b]*(long)b;
        sum = sum + cnt[b]*(long)c ;
        cnt[b] = 0;
        pn(sum);
    }
 }

    long pow(long a, long b) {
        long result = 1;
        while (b > 0) {
            if (b % 2 == 1) result = (result * a) % mod;
            b /= 2;
            a = (a * a) % mod;
        }
        return result;
    }

    void print(Object o) {
        System.out.println(o);
        System.out.flush();
    }

    long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    //output methods
    private void pn(Object o) {
        out.println(o);
    }
    private void p(Object o) {
        out.print(o);
    }
    private ArrayList < ArrayList < Integer >> ng(int n, int e) {
        ArrayList < ArrayList < Integer >> g = new ArrayList < > ();
        for (int i = 0; i <= n; ++i) g.add(new ArrayList < > ());

        for (int i = 0; i < e; ++i) {
            int u = ni(), v = ni();
            g.get(u).add(v);
            g.get(v).add(u);
        }

        return g;
    }

    private ArrayList < ArrayList < pair >> nwg(int n, int e) {
        ArrayList < ArrayList < pair >> g = new ArrayList < > ();
        for (int i = 0; i <= n; ++i) g.add(new ArrayList < > ());

        for (int i = 0; i < e; ++i) {
            int u = ni(), v = ni(), w = ni();
            g.get(u).add(new pair(w, v));
            g.get(v).add(new pair(w, u));
        }

        return g;
    }

    //input methods
    private byte[] inbuf = new byte[1024];
    public int lenbuf = 0, ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }
    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b));
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }
    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private void tr(Object...o) {
        if (INPUT.length() > 0) System.out.println(Arrays.deepToString(o));
    }
    void watch(Object...a) throws Exception {
        int i = 1;
        print("watch starts :");
        for (Object o: a) {
            //print(o);
            boolean notfound = true;
            if (o.getClass().isArray()) {

                String type = o.getClass().getName().toString();
                //print("type is "+type);
                switch (type) {
                    case "[I":
                        {
                            int[] test = (int[]) o;
                            print(i + " " + Arrays.toString(test));
                            break;
                        }
                    case "[[I":
                        {
                            int[][] obj = (int[][]) o;

                            print(i + " " + Arrays.deepToString(obj));
                            break;
                        }
                    case "[J":
                        {

                            long[] obj = (long[]) o;
                            print(i + " " + Arrays.toString(obj));
                            break;
                        }
                    case "[[J":
                        {

                            long[][] obj = (long[][]) o;
                            print(i + " " + Arrays.deepToString(obj));
                            break;
                        }
                    case "[D":
                        {

                            double[] obj = (double[]) o;
                            print(i + " " + Arrays.toString(obj));
                            break;
                        }
                    case "[[D":
                        {

                            double[][] obj = (double[][]) o;
                            print(i + " " + Arrays.deepToString(obj));
                            break;
                        }
                    case "[Ljava.lang.String":
                        {

                            String[] obj = (String[]) o;
                            print(i + " " + Arrays.toString(obj));
                            break;
                        }
                    case "[[Ljava.lang.String":
                        {

                            String[][] obj = (String[][]) o;
                            print(i + " " + Arrays.deepToString(obj));
                            break;
                        }
                    case "[C":
                        {
                            char[] obj = (char[]) o;
                            print(i + " " + Arrays.toString(obj));
                            break;
                        }
                    case "[[C":
                        {

                            char[][] obj = (char[][]) o;
                            print(i + " " + Arrays.deepToString(obj));
                            break;
                        }

                    default:
                        {
                            print(i + " type not identified");
                            break;
                        }
                }
                notfound = false;

            }
            if (o.getClass() == ArrayList.class) {
                print(i + " al: " + o);
                notfound = false;
            }
            if (o.getClass() == HashSet.class) {
                print(i + " hs: " + o);
                notfound = false;
            }
            if (o.getClass() == TreeSet.class) {
                print(i + " ts: " + o);
                notfound = false;
            }
            if (o.getClass() == TreeMap.class) {
                print(i + " tm: " + o);
                notfound = false;
            }
            if (o.getClass() == HashMap.class) {
                print(i + " hm: " + o);
                notfound = false;
            }
            if (o.getClass() == LinkedList.class) {
                print(i + " ll: " + o);
                notfound = false;
            }
            if (o.getClass() == PriorityQueue.class) {
                print(i + " pq : " + o);
                notfound = false;
            }
            if (o.getClass() == pair.class) {
                print(i + " pq : " + o);
                notfound = false;
            }

            if (notfound) {
                print(i + " unknown: " + o);
            }
            i++;
        }
        print("watch ends ");
    }

}