import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        AReorder solver = new AReorder();
        int testCount = Integer.parseInt(in.next());
        for (int i = 1; i <= testCount; i++)
            solver.solve(i, in, out);
        out.close();
    }

    static class AReorder {
        public void solve(int testNumber, InputReader in, OutputWriter out) {

            int n = in.readInt(), m = in.readInt();

            int[] arr = in.readIntArray(n);

            int sum = (int) ArrayUtils.sumArray(arr);

            out.printLine(sum == m ? "YES" : "NO");
        }

    }

    static class ArrayUtils {
        public static long sumArray(int[] array) {
            return new IntArray(array).sum();
        }

    }

    static interface IntCollection extends IntStream {
        public int size();

    }

    static interface IntList extends IntReversableCollection {
        public abstract int get(int index);

        public abstract void removeAt(int index);

        default public IntIterator intIterator() {
            return new IntIterator() {
                private int at;
                private boolean removed;

                public int value() {
                    if (removed) {
                        throw new IllegalStateException();
                    }
                    return get(at);
                }

                public boolean advance() {
                    at++;
                    removed = false;
                    return isValid();
                }

                public boolean isValid() {
                    return !removed && at < size();
                }

                public void remove() {
                    removeAt(at);
                    at--;
                    removed = true;
                }
            };
        }

    }

    static abstract class IntAbstractStream implements IntStream {
        public String toString() {
            StringBuilder builder = new StringBuilder();
            boolean first = true;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                if (first) {
                    first = false;
                } else {
                    builder.append(' ');
                }
                builder.append(it.value());
            }
            return builder.toString();
        }

        public boolean equals(Object o) {
            if (!(o instanceof IntStream)) {
                return false;
            }
            IntStream c = (IntStream) o;
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                if (it.value() != jt.value()) {
                    return false;
                }
                it.advance();
                jt.advance();
            }
            return !it.isValid() && !jt.isValid();
        }

        public int hashCode() {
            int result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result *= 31;
                result += it.value();
            }
            return result;
        }

    }

    static interface IntReversableCollection extends IntCollection {
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = readInt();
            }
            return array;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class IntArray extends IntAbstractStream implements IntList {
        private int[] data;

        public IntArray(int[] arr) {
            data = arr;
        }

        public int size() {
            return data.length;
        }

        public int get(int at) {
            return data[at];
        }

        public void removeAt(int index) {
            throw new UnsupportedOperationException();
        }

    }

    static interface IntIterator {
        public int value() throws NoSuchElementException;

        public boolean advance();

        public boolean isValid();

    }

    static interface IntStream extends Iterable<Integer>, Comparable<IntStream> {
        public IntIterator intIterator();

        default public Iterator<Integer> iterator() {
            return new Iterator<Integer>() {
                private IntIterator it = intIterator();

                public boolean hasNext() {
                    return it.isValid();
                }

                public Integer next() {
                    int result = it.value();
                    it.advance();
                    return result;
                }
            };
        }

        default public int compareTo(IntStream c) {
            IntIterator it = intIterator();
            IntIterator jt = c.intIterator();
            while (it.isValid() && jt.isValid()) {
                int i = it.value();
                int j = jt.value();
                if (i < j) {
                    return -1;
                } else if (i > j) {
                    return 1;
                }
                it.advance();
                jt.advance();
            }
            if (it.isValid()) {
                return 1;
            }
            if (jt.isValid()) {
                return -1;
            }
            return 0;
        }

        default public long sum() {
            long result = 0;
            for (IntIterator it = intIterator(); it.isValid(); it.advance()) {
                result += it.value();
            }
            return result;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}


import java.util.Scanner;

public class ProblemA {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();
        for(int i = 0; i<t; i++){
            int n = sc.nextInt();
            int m = sc.nextInt();
            int sum = 0;
            for(int j=0; j<n; j++){
                sum=sum+sc.nextInt();
            }
            if(sum == m){
                System.out.println("YES");
            }
            else{
                System.out.println("NO");
            }
        }
    }
}


import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int testCases = sc.nextInt();
	    for(int i=0;i<testCases;i++){
	        int n = sc.nextInt();
	        int m = sc.nextInt();
	        int a[] = new int[n];
	        int sum=0;
	        for(int j=0;j<n;j++){
	            a[j] = sc.nextInt();
	            sum+=a[j];
	        }
	        if(sum==m){
	            System.out.println("YES");
	        }
	        else{
	            System.out.println("NO");
	        }
	    }
	}
}


import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int testCases = sc.nextInt();
	    for(int i=0;i<testCases;i++){
	        int n = sc.nextInt();
	        int m = sc.nextInt();
	        int a[] = new int[n];
	        int sum=0;
	        for(int j=0;j<n;j++){
	            a[j] = sc.nextInt();
	            sum+=a[j];
	        }
	        if(sum==m){
	            System.out.println("YES");
	            return;
	        }
	        else{
	            System.out.println("NO");
	            return;
	        }
	    }
	}
}


import java.io.*;
import java.util.*;

public class T {
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int loop=sc.nextInt();

        while(loop-->0){
            int n=sc.nextInt();
            int m=sc.nextInt();
            int sum=0;
            while(n-->0){sum+=sc.nextInt();}
            if(sum==m)System.out.println("YES");
            else System.out.println("NO");
        }

    }
}


//package codeforce.div2.r678;

import java.util.Scanner;

public class A {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int t = sc.nextInt();
      for (int i = 0; i < t; i++) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        long sum = 0;
        for (int j = 0; j < n; j++) {
          sum += sc.nextInt();
        }
        System.out.println(sum == k ? "YES" : "NO");
      }
    }
  }

}


package googleKickStart;

import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int testcase = 1;

		while (testcase <= t) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] arr = new int[n];

			for(int i=0; i<n; i++) {
				arr[i] = sc.nextInt();
				m -= arr[i];
			}

			if(m == 0)
				System.out.println("YES");
			else
				System.out.println("NO");
			testcase++;
		}
	}

}


import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int testcase = 1;

		while (testcase <= t) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[] arr = new int[n];

			for(int i=0; i<n; i++) {
				arr[i] = sc.nextInt();
				m -= arr[i];
			}

			if(m == 0)
				System.out.println("YES");
			else
				System.out.println("NO");
			testcase++;
		}
	}

}


package com.trn.codeforce;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        //Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine().trim());

        while(t-- > 0){
            StringTokenizer line = new StringTokenizer(br.readLine().trim());
            int n = Integer.parseInt(line.nextToken().trim());
            int m = Integer.parseInt(line.nextToken().trim());

            StringTokenizer line2 = new StringTokenizer(br.readLine().trim());
            int[] arr = new int[n];

            int total = 0;
            for(int i = 0; i < n; i++){
                arr[i] = Integer.parseInt(line2.nextToken().trim());
                total += arr[i];
            }

            System.out.println((total == m)? "YES" : "NO");

        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        //Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine().trim());

        while(t-- > 0){
            StringTokenizer line = new StringTokenizer(br.readLine().trim());
            int n = Integer.parseInt(line.nextToken().trim());
            int m = Integer.parseInt(line.nextToken().trim());

            StringTokenizer line2 = new StringTokenizer(br.readLine().trim());
            int[] arr = new int[n];

            int total = 0;
            for(int i = 0; i < n; i++){
                arr[i] = Integer.parseInt(line2.nextToken().trim());
                total += arr[i];
            }

            System.out.println((total == m)? "YES" : "NO");

        }

    }
}


import java.util.Scanner;

public class Reorder {

  public static void main(String[] args) {
    Scanner mySnanner = new Scanner(System.in);
    int iNumTestCases = mySnanner.nextInt();

    //-- for each test case
    for(int k = 0; k < iNumTestCases; k++) {
      int iSizeOfA = mySnanner.nextInt();
      int m = mySnanner.nextInt();

      //-- Read array
      boolean bContainsZero = false;
      int a[] = new int[iSizeOfA];
      for(int i = 0; i < iSizeOfA; i++) {
        a[i] = mySnanner.nextInt();
        if(a[i] == 0) {
          bContainsZero = true;
        }
      }

      if(bContainsZero)
        System.out.println("NO");
      else
        System.out.println("YES");
    }
  }
}


import java.util.Scanner;

public class Reorder {

  public static void main(String[] args) {
    Scanner mySnanner = new Scanner(System.in);
    int iNumTestCases = mySnanner.nextInt();

    //-- for each test case
    for(int k = 0; k < iNumTestCases; k++) {
      int iSizeOfA = mySnanner.nextInt();
      int m = mySnanner.nextInt();

      //-- Read array
      boolean bContainsZero = false;
      int a[] = new int[iSizeOfA];
      for(int i = 0; i < iSizeOfA; i++) {
        a[i] = mySnanner.nextInt();
        if(a[i] == 0) {
          bContainsZero = true;
          break;
        }
      }

      if(bContainsZero)
        System.out.println("NO");
      else
        System.out.println("YES");
    }
  }
}


import java.util.Scanner;

public class Reorder {

  public static void main(String[] args) {
    Scanner mySnanner = new Scanner(System.in);
    int iNumTestCases = mySnanner.nextInt();

    //-- for each test case
    for(int k = 0; k < iNumTestCases; k++) {
      int iSizeOfA = mySnanner.nextInt();
      int m = mySnanner.nextInt();

      //-- Read array
      int iSum = 0;
      int a[] = new int[iSizeOfA];
      for(int i = 0; i < iSizeOfA; i++) {
        a[i] = mySnanner.nextInt();
        iSum += a[i];
      }

      if(m == iSum)
        System.out.println("YES");
      else
        System.out.println("NO");
    }
  }
}


import java.util.*;
public class codeforces{
  public static void main(String args[]){
         Scanner sc=new Scanner(System.in);
         int n=sc.nextInt();
         int m=sc.nextInt();
         int sum=0;
         for(int i=0;i<n;i++){
            int a=sc.nextInt();
            sum+=a;
            }
            if(sum==m){System.out.println("YES");}
            else{System.out.println("NO");}
    }

}


import java.util.*;
public class codeforces{
  public static void main(String args[]){
         Scanner sc=new Scanner(System.in);
         int t=sc.nextInt();
         while(t-->0){
         int n=sc.nextInt();
         int m=sc.nextInt();
         int sum=0;
         for(int i=0;i<n;i++){
            int a=sc.nextInt();
            sum+=a;
            }
            if(sum==m){System.out.println("YES");}
            else{System.out.println("NO");}
    }
}

}


//package codeforce;

import java.util.Scanner;

public class perestanovka {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] a = new int[n];
            int cnt = 0;
            for (int j = 0; j < n; j++) {
                a[i] = sc.nextInt();
                cnt += a[i];
            }
            if(cnt == m)
                System.out.println("YES");
            else
                System.out.println("NO");
        }
    }
}


import java.util.*

fun main () {
    val sc = Scanner(System.`in`);
    val n = sc.nextInt();
    var i = 0;
    while (i < n) {
        val num:Long = sc.nextLong();
        if (num <= 999)
            println("$num");
        else if(num <= 999500) {
            var ans  = (num + 500) / 1000;
            println("$ans" + "K");
        }
        else {
            var ans  = (num + 500000) / 1000000;
            println("$ans" + "K");
        }
        i++;
    }
}


fun main() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len < 7 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
            else -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
        }
    }
}


fun main() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        val s = readLine()!!
        val len = s.length
        when {
            s.toInt() < 1000 -> println("$s")
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {
    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len < 7 -> {
                if (len == 6 && s[0] >= '5') {
                    println("1M")
                } else {
                    val fs = s.substring(0, len - 3).toInt()
                    println("${if (s[len-3] >= '5') fs+1 else fs}K")
                }
            }
            else -> {
                val fs = s.substring(0, len - 6).toInt()
                println("${if (s[len-6] >= '5') fs+1 else fs}M")
            }
        }
    }
}


fun main() {

    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        val s = readLine()!!
        val len = s.length
        when {
            s.toInt() < 1000 -> println("$s")
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).toInt()
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).toInt()
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {

    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        s.toIntOrNull() ?: continue
        if (s.contains('M')) {
            println(s)
            continue
        } else if (s.contains('K')) {
            s = s.substring(0, len - 1)
            if (s.length < 4) {
                println("${s}K")
                continue
            } else {
                s = "${s}000"
            }
        } else if (len < 4) {
            println(s)
            continue
        }
        when {
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {
    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var case = readLine()!!.toInt()
        when {
            case < 1_000 -> println(case)
            case < 999_500 -> {
                println("${case.div(1_000).plus(
                    if (case.div(100) >= 5) 1 else 0
                )}K")
            }
            case < 1_000_000 -> println("1M")
            else -> {
                println("${case.div(1_000_000).plus(
                    if (case.div(100_000) >= 5) 1 else 0
                )}M")
            }
        }
    }
}


fun main() {
    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len < 7 -> {
                val fs = s.substring(0, len - 3).toInt()
                val ff = if (s[len-3] >= '5') fs+1 else fs
                if (ff > 999) println("1M")
                else println("${ff}K")
            }
            else -> {
                val fs = s.substring(0, len - 6).toInt()
                println("${if (s[len-6] >= '5') fs+1 else fs}M")
            }
        }
    }
}


fun main() {
    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len < 7 -> {
                val fs = s.substring(0, len - 3).toInt()
                println("${if (s[len-4] >= '5') fs+1 else fs}K")
            }
            else -> {
                val fs = s.substring(0, len - 6).toInt()
                println("${if (s[len-7] >= '5') fs+1 else fs}M")
            }
        }
    }
}


fun main() {

    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        s = s.replace("K", "000")
        s = s.replace("M", "000000")
        when {
            s.toInt() < 1000 -> println(s)
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {

    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        if (s.contains('M')) {
            println(s)
            continue
        } else if (s.contains('K')) {
            s = s.substring(0, len - 1)
            if (s.length < 4) {
                println("${s}K")
                continue
            } else {
                s = "${s}000"
            }
        } else if (len < 4) {
            println(s)
            continue
        }
        when {
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {

    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        if (s.contains('M')) {
            println(s)
            continue
        }
        if (s.contains('K')) {
            s = s.replace("K", "000")
            if (s.length < 7) {
                println(s)
                continue
            }
        }
        when {
            s.toInt() < 1000 -> println(s)
            len >= 6 -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
            len >= 3 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
        }
    }
}


fun main() {
    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len < 7 -> {
                val fs = s.substring(0, len - 3).toIntOrNull() ?: 0
                val bs = s.substring(len - 3).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}K")
            }
            else -> {
                val fs = s.substring(0, len - 6).toIntOrNull() ?: 0
                val bs = s.substring(len - 6).first() - '0'
                println("${if (bs >= 5) fs+1 else fs}M")
            }
        }
    }
}


fun main() {
    likeDisplayProblem()
}

fun likeDisplayProblem() {
    val n = readLine()!!.toInt()
    for (i in 1..n) {
        var s = readLine()!!
        val len = s.length
        when {
            len < 4 -> println(s)
            len < 7 -> {
                if (len == 6 && s[0] >= '5') {
                    println("1M")
                } else {
                    val fs = s.substring(0, len - 3).toInt()
                    println("${if (s[len-4] >= '5') fs+1 else fs}K")
                }
            }
            else -> {
                val fs = s.substring(0, len - 6).toInt()
                println("${if (s[len-7] >= '5') fs+1 else fs}M")
            }
        }
    }
}


import kotlin.math.round

fun main() {
//    println(humanReadableCount(6499))
//    println(humanReadableCount(6500))
//    println(humanReadableCount(6499999))
//    println(humanReadableCount(6500000))

    val lineCount = readLine()?.toInt() ?: 0

    repeat(lineCount) {
        println(humanReadableCount(readLine()?.toInt() ?: 0))
    }
}

private fun humanReadableCount(count: Int): String = when (count) {
    in 0..999 -> count.toString()
    in 1000..999499 -> "${round((count + 0.5) / 1000).toInt()}K"
    else -> "${round((count + 0.5) / 1000000).toInt()}M"
}


import kotlin.math.round

fun main() {
    val lineCount = readLine()?.toInt() ?: 0

    repeat(lineCount) {
        @Suppress("MoveVariableDeclarationIntoWhen")
        val likeCount = readLine()?.toInt() ?: 0

        val humanReadableCount = when (likeCount) {
            in 0..999 -> likeCount.toString()
            in 1000..999499 -> "${round(likeCount / 1000.0).toInt()}K"
            else -> "${round(likeCount / 1000000.0).toInt()}M"
        }

        println(humanReadableCount)
    }
}


import kotlin.math.round

fun main() {
    val lineCount = readLine()?.toInt() ?: 0

    repeat(lineCount) {
        val humanReadableCount = when (readLine()?.toInt() ?: 0) {
            in 0..949 -> it.toString()
            in 950..999499 -> "${round(it / 1000.0).toInt()}K"
            else -> "${round(it / 1000000.0).toInt()}M"
        }

        println(humanReadableCount)
    }
}


import kotlin.math.round

fun main() {
    val lineCount = readLine()?.toInt() ?: 0

    repeat(lineCount) {
        val humanReadableCount = when (readLine()?.toInt() ?: 0) {
            in 0..949 -> (readLine()?.toInt() ?: 0).toString()
            in 950..999499 -> "${round((readLine()?.toInt() ?: 0) / 1000.0).toInt()}K"
            else -> "${round((readLine()?.toInt() ?: 0) / 1000000.0).toInt()}M"
        }

        println(humanReadableCount)
    }
}


import kotlin.math.round

fun main() {
    val lineCount = readLine()?.toInt() ?: 0

    repeat(lineCount) {
        @Suppress("MoveVariableDeclarationIntoWhen")
        val likeCount = readLine()?.toInt() ?: 0

        val humanReadableCount = when (likeCount) {
            in 0..949 -> likeCount.toString()
            in 950..999499 -> "${round(likeCount / 1000.0).toInt()}K"
            else -> "${round(likeCount / 1000000.0).toInt()}M"
        }

        println(humanReadableCount)
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define trace(x) cout << #x "=" << x << endl
#define int128 __int128

#define int long long

const int mod = 1e9 + 7;

const int maxn = 4e5 + 10;

int a[maxn];
int t[maxn];
pair<int, int> category[maxn];

signed main() {
    cin.tie();
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> t[i];
    for (int i = 0; i < n; ++i)
        category[i] = {a[i], t[i]};
    sort(category, category + n);
    multiset<int> now;
    int sum_now = 0;
    int res = 0;
    int cnt_now = -1;
    for (int i = 0; i < n || !now.empty();) {
        int j = i;
        while (j < n && (now.empty() || cnt_now == category[j].first)) {
            now.insert(category[j].second);
            cnt_now = category[j].first;
            sum_now += category[j].second;
            ++j;
        }
        assert(!now.empty());
        sum_now -= *now.rbegin();
        now.erase(--now.end());
        res += sum_now;
        i = j;
        cnt_now++;
    }
    cout << res;
}


import java.util.*

fun fix(s: Int): String =
    when {
        s < 1000 -> s.toString()
        s > 999500 ->
            "${(s + 500_000) / 1_000_000}M"
        else ->
            "${(s + 500) / 1_000}K"
    }

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = sc.nextInt()
    repeat(t) {
        println(fix(sc.nextInt()))
    }
}


package `Kotlin Heroes 3`.A

import java.util.*

fun fix(s: Int): String =
    when {
        s < 1000 -> s.toString()
        s > 999500 ->
            "${(s + 500_000) / 1_000_000}M"
        else ->
            "${(s + 500) / 1_000}K"
    }

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = sc.nextInt()
    repeat(t) {
        println(fix(sc.nextInt()))
    }
}


import java.util.*

fun fix(s: Int): String =
    when {
        s < 1000 -> s.toString()
        s >= 999500 ->
            "${(s + 500_000) / 1_000_000}M"
        else ->
            "${(s + 500) / 1_000}K"
    }

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val t = sc.nextInt()
    repeat(t) {
        println(fix(sc.nextInt()))
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 1000) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 1000000) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + roundTo - 1) / roundTo * roundTo
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 1000) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 1000000) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = num / roundTo * roundTo
            num = (num / roundTo)
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 1000) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 1000000) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + roundTo - 1) / roundTo
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 1000) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 1000000) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + (roundTo / 2)) / roundTo * roundTo
            num = (num / roundTo)
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 999) {
            roundTo = 1000
            postfix = "K"
        }

        if (num >= 999999) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + (roundTo / 2)) / roundTo * roundTo
            num = (num / roundTo)
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 1000) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 1000000) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = ((num + roundTo - 1) / roundTo) - roundTo
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 999) {
            roundTo = 1000
            postfix = "K"
        }

        if (num >= 999500) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + (roundTo / 2)) / roundTo * roundTo
            num = (num / roundTo)
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 1000) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 1000000) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + roundTo - 1) / roundTo * roundTo
            num = (num / roundTo)
        }

        println(num.toString() + postfix)
    }
}


fun main(vararg args: String) {
    val numRounds = readLine()?.toInt() ?: 0

    for (x in 0 until numRounds) {
        var num: Int = readLine()?.toInt() ?: 0

        var roundTo: Int = 0
        var postfix = ""

        if (num > 999) {
            roundTo = 1000
            postfix = "K"
        }

        if (num > 999999) {
            roundTo = 1000000
            postfix = "M"
        }

        if (roundTo > 0) {
            num = (num + (roundTo / 2)) / roundTo * roundTo
            num = (num / roundTo)
        }

        println(num.toString() + postfix)
    }
}


fun main() {
    val t = readLine()!!.toInt()
    repeat(t) {
        val value = readLine()!!.toLong()
        when {
            value > 1_000_000 -> println("${(value / 1_000_000F).roundToInt()}M")
            value > 1_000 -> println("${(value / 1_000F).roundToInt()}k")
            else -> println(value)
        }
    }
}


import kotlin.math.roundToInt

fun main() {
    val t = readLine()!!.toInt()
    repeat(t) {
        val value = readLine()!!.toLong()
        when {
            value >= 999_500 -> println("${(value / 1_000_000F).roundToInt()}M")
            value >= 1_000 -> println("${(value / 1_000F).roundToInt()}K")
            else -> println(value)
        }
    }
}


import kotlin.math.roundToInt

fun main() {
    val t = readLine()!!.toInt()
    repeat(t) {
        val value = readLine()!!.toLong()
        when {
            value > 1_000_000 -> println("${(value / 1_000_000F).roundToInt()}M")
            value > 1_000 -> println("${(value / 1_000F).roundToInt()}K")
            else -> println(value)
        }
    }
}


import kotlin.math.roundToInt

fun main() {
    (1..readLine()!!.toInt())
        .map { readLine() }
        .map { it!!.toInt() }
        .forEach { value ->
            when {
                value >= 999_500 -> println("${(value / 1_000_000F).roundToInt()}M")
                value >= 1_000 -> println("${(value / 1_000F).roundToInt()}K")
                else -> println(value)
            }
        }
}


import kotlin.math.roundToInt

fun main() {
    val t = readLine()!!.toInt()
    repeat(t) {
        val value = readLine()!!.toLong()
        when {
            value >= 1_000_000 -> println("${(value / 1_000_000F).roundToInt()}M")
            value >= 1_000 -> println("${(value / 1_000F).roundToInt()}K")
            else -> println(value)
        }
    }
}


import kotlin.math.roundToInt

fun main() {
    (1..readLine()!!.toInt())
        .map { readLine() }
        .map { it!!.toLong() }
        .forEach { value ->
            when {
                value >= 999_500 -> println("${(value / 1_000_000.00).roundToInt()}M")
                value >= 1_000 -> println("${(value / 1_000.00).roundToInt()}K")
                else -> println(value)
            }
        }
}


import kotlin.math.roundToInt

fun main() {
    (1..readLine()!!.toInt())
        .map { readLine() }
        .map { it!!.toLong() }
        .forEach { value ->
            when {
                value >= 999_500 -> println("${(value / 1_000_000F).roundToInt()}M")
                value >= 1_000 -> println("${(value / 1_000F).roundToInt()}K")
                else -> println(value)
            }
        }
}


import kotlin.math.roundToInt

fun main() {
    val t = readLine()!!.toInt()
    repeat(t) {
        val value = readLine()!!.toLong()
        when {
            value > 1_000_000 -> println("${(value / 1_000_000F).roundToInt()}M")
            value > 1_000 -> println("${(value / 1_000F).roundToInt()}k")
            else -> println(value)
        }
    }
}


fun main() {
    val t = readLine()!!.toInt()
    repeat(t) {
        val value = readLine()!!.toLong()
        when {
            value >= 999_500 -> println("${(value / 1_000_000F).roundToInt()}M")
            value >= 1_000 -> println("${(value / 1_000F).roundToInt()}K")
            else -> println(value)
        }
    }
}


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded > 500) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    for (i in 1..count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded == 1000) {
                "1M"
            } else {
                "${round(number / 1000.0).toInt()}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    for (i in 0..9) {
        plainNumbers.add(readInt())
    }
    plainNumbers.removeAt(0)

    plainNumbers.forEach {
        println(convert(it))
    }

}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> "${round(number / 1000.0).toInt()}K"
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    if (number < 0) return ""
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded >= 990) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded == 1000) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.ceil

fun main() {
    val plainNumbers = mutableListOf<Int>()
    for (i in 0..9) {
        plainNumbers.add(readInt())
    }
    plainNumbers.removeAt(0)

    plainNumbers.forEach {
        println(convert(it))
    }

}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> "${ceil(number / 1000.0).toInt()}K"
        else -> "${ceil(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.ceil

fun main() {
    val plainNumbers = mutableListOf<Int>()
    for (i in 0..9) {
        plainNumbers.add(readInt())
    }
    plainNumbers.remove(0)

    plainNumbers.forEach {
        println(convert(it))
    }

}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> "${ceil(number / 1000.0).toInt()}K"
        else -> "${ceil(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded >= 500) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    for (i in 0..9) {
        plainNumbers.add(readInt())
    }
    plainNumbers.removeAt(0)

    plainNumbers.forEach {
        println(convert(it))
    }

}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded == 1000) {
                "1M"
            } else {
                "${round(number / 1000.0).toInt()}K"
            }

        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */
fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded == 1000) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    if (number < 0) return ""
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded >= 1000) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.ceil

fun main() {
    val plainNumbers = mutableListOf<Int>()
    for (i in 0..9) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }

}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> "${ceil(number / 1000.0).toInt()}K"
        else -> "${ceil(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded == 1000) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.roundToInt

/**
 * Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools
 */
fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = (number / 1000.0).roundToInt()
            if (rounded == 1000) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${(number / 1000000.0).roundToInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


import kotlin.math.round

fun main() {
    val plainNumbers = mutableListOf<Int>()
    val count = readInt()
    if (count < 1 || count > 1000) {
        return
    }
    for (i in 0 until count) {
        plainNumbers.add(readInt())
    }

    plainNumbers.forEach {
        println(convert(it))
    }
}

fun convert(number: Int): String {
    return when (number) {
        in 0..999 -> number.toString()
        in 1000..999999 -> {
            val rounded = round(number / 1000.0).toInt()
            if (rounded >= 500) {
                "1M"
            } else {
                "${rounded}K"
            }
        }
        else -> "${round(number / 1000000.0).toInt()}M"
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

//9
//999
//123
//0
//1782
//31415926
//1500
//999999
//35499710
//2000000000

//999
//123
//0
//2K
//31M
//2K
//1M
//35M
//2000M


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println("($dp)M")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println("($dp)K")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println("$dpM")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println("$dpK")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println(dp.toString() + "M")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println(dp.toString() + "K")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=999500
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println(dp.toString() + "M")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println(dp.toString() + "K")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println("$dp M")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println("$dp K")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    out!!.print(dp.toString() + "M")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println("$dp K")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println(dp.toString() + "M")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println("$dp K")
		}
		else
		{
		    println("$dp")
		}
	}
}


fun readint()=readLine()!!.toInt()
fun main() {
    var n=readint()
    var d=1000000
    var p=1000
    var curr=0
    for(i in 0 until n)
	{
		var dp=readint()
		if(dp>=d)
		{
		    dp+=500000
		    dp/=1000000
		    println("$dpM")
		}
		else if(dp>=p)
		{
		    dp+=500
		    dp/=1000
		    println("$dpK")
		}
		else
		{
		    println("$dp")
		}
	}
}


#include<bits/stdc++.h>
#include <sys/time.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> V;
#define F first
#define S second
#define mod 1000000007
const ll INF=3000000000000000000;
#define MAXN 200005
#define PI 3.1415926535897932384626433832795
#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();

ll power(ll x, ll y,ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
        res = (res*x)%p;
        y = y>>1;
        x = (x*x)%p;
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T=1,xp=1;
    //cin>>T;

    while(T--)
    {
        struct timeval start, end;
        ll i=0,h,j=0,n,x=0,y=0,m,l=0,k=0,r=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
        gettimeofday(&start, NULL);
        cin>>x>>y>>n;
        ll a[n];
        for(i=0;i<n;i++){
            cin>>a[i];
        }
        ll ans=0;
        for(i=0;i<n;i++){
            ll temp=(a[i]-x+(x-y-1))/(x-y);
            if(temp<0)
                temp=0;
            ans+=temp+1;
        }
        cout<<ans<<endl;

        /*gettimeofday(&end, NULL);
        double time_taken;

        time_taken = (end.tv_sec - start.tv_sec) * 1e6;
        time_taken = (time_taken + (end.tv_usec -
                                  start.tv_usec)) * 1e-6;

        cout << "Time taken by program is : " << fixed
             << time_taken << setprecision(6);
        cout << " sec" << endl; */
        xp++;
    }

}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(args: Array<String>) {
   var t = readInt()
   for(i in 0..t-1){
   		var x = readInt()
   		if(x<=999){
   			println(x)
   		}
   		else if(x>=1000&&x<=999999){
   			var ans = (x)/1000
   			if(x>=ans*1000+500){
   				ans++
   			}
   			print(ans);
   			println("K")
   		}
   		else{
   			var ans = (x)/1000000
   			if(x>=ans*1000000+500000){
   				ans++
   			}
   			print(ans);
   			println("M")
   		}
   }

}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(args: Array<String>) {
   var t = readInt()
   for(i in 0..t-1){
   		var x = readInt()
   		if(x<=999){
   			println(x)
   		}
   		else if(x>=1000&&x<=999999){
   			var ans = (x)/1000
   			if(x>=ans*1000+500){
   				ans++
   			}
   			if(ans!=1000){
   				print(ans);
   				println("K")
   			}
   			else{
   				print(1)
   				println("M")
   			}
   		}
   		else{
   			var ans = (x)/1000000
   			if(x>=ans*1000000+500000){
   				ans++
   			}
   			print(ans);
   			println("M")
   		}
   }

}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(args: Array<String>) {
   var t = readInt()
   for(i in 0..t-1){
   		var x = readInt()
   		if(x<=999){
   			println(x)
   		}
   		else if(x>=1000&&x<=999000){
   			var ans = (x+999)/1000
   			print(ans);
   			println("K")
   		}
   		else{
   			var ans = (x+99999)/1000000
   			print(ans);
   			println("M")
   		}
   }

}


private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

fun main(args: Array<String>) {
   var t = readInt()
   for(i in 0..t-1){
   		var x = readInt()
   		if(x<=999){
   			println(x)
   		}
   		else if(x>=1000&&x<=999000){
   			var ans = (x)/1000
   			if(x>=ans*1000+500){
   				ans++
   			}
   			print(ans);
   			println("K")
   		}
   		else{
   			var ans = (x)/1000000
   			if(x>=ans*1000000+500000){
   				ans++
   			}
   			print(ans);
   			println("M")
   		}
   }

}


import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    val t = scanner.nextLine()

    repeat(t.toInt()) {
        val num = scanner.nextLine()

        if (num.length <= 3) println(num)
        else if (num.length in 4..6) {
            val hundred = num.lastIndex - 3
            if (num[hundred + 1].toInt() >= 5) {
                val answer = num.slice(0..num.lastIndex - 3).toInt()
                if (answer == 999) println("1M")
                else println("${answer + 1}K")
            } else println("${num.slice(0..num.lastIndex - 3)}K")
        } else {
            val thousand = num.lastIndex - 5
            if (num[thousand].toInt() >= 5) {
                println("${num.slice(0..num.lastIndex - 6).toLong()}M")
            } else println("${num.slice(0..num.lastIndex - 6)}M")
        }
    }
}


import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    val t = scanner.nextLine()

    repeat(t.toInt()) {
        val num = scanner.nextLine()

        if (num.length <= 3) println(num)
        else if (num.length in 4..6) {
            val hundred = num.lastIndex - 3
            if (num[hundred + 1].toInt() >= 5) {
                val answer = num.slice(0..num.lastIndex - 3).toInt()
                println("${answer + 1}K")
            } else println("${num.slice(0..num.lastIndex - 3)}K")
        } else {
            val thousand = num.lastIndex - 5
            if (num[thousand].toInt() >= 5) {
                println("${num.slice(0..num.lastIndex - 6).toLong()}M")
            } else println("${num.slice(0..num.lastIndex - 6)}M")
        }
    }
}


package KotlinHeroes3

import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    val t = scanner.nextLine()

    repeat(t.toInt()) {
        val num = scanner.nextLine()

        if (num.length <= 3) println(num)
        else if (num.length in 4..6) {
            val hundred = num.lastIndex - 3
            if (num[hundred + 1].toInt() >= 5) {
                val answer = num.slice(0..num.lastIndex - 3).toInt()
                println("${answer + 1}K")
            } else println("${num.slice(0..num.lastIndex - 3)}K")
        } else {
            val thousand = num.lastIndex - 5
            if (num[thousand].toInt() >= 5) {
                println("${num.slice(0..num.lastIndex - 6).toLong()}M")
            } else println("${num.slice(0..num.lastIndex - 6)}M")
        }
    }
}


import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    val t = scanner.nextLine()

    repeat(t.toInt()) {
        val num = scanner.nextLine()

        if (num.length <= 3) println(num)
        else if (num.length in 4..6) {
            val hundred = num.lastIndex - 3
            if (num[hundred + 1].toInt() >= 5) {
                val answer = num.slice(0..num.lastIndex - 3).toInt()
                if (answer == 1000) println("1M")
                else println("${answer + 1}K")
            } else println("${num.slice(0..num.lastIndex - 3)}K")
        } else {
            val thousand = num.lastIndex - 5
            if (num[thousand].toInt() >= 5) {
                println("${num.slice(0..num.lastIndex - 6).toLong()}M")
            } else println("${num.slice(0..num.lastIndex - 6)}M")
        }
    }
}


import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    val t = scanner.nextLine()

    for (i in 0 until t.toInt()) {
        val num = scanner.nextLine()

        if (num.length <= 3) println(num)
        else if (num.length in 4..6) {
            val hundred = num.lastIndex - 2
            if (num[hundred].toString().toInt() >= 5) {
                val answer = num.slice(0..num.lastIndex - 3).toInt()
                if (answer == 999) println("1M")
                else println("${answer + 1}K")
            } else println("${num.slice(0..num.lastIndex - 3)}K")
        } else {//1000000
            val thousand = num.lastIndex - 5
            if (num[thousand].toString().toInt() >= 5) {
                println("${num.slice(0..num.lastIndex - 6).toLong() + 1}M")
            } else println("${num.slice(0..num.lastIndex - 6)}M")
        }
    }
}


/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */
import kotlin.math.roundToInt
import java.util.Scanner
fun main() {
    val read = Scanner(System.`in`)
    val t=read.nextInt()
    for(i in 1..t){
        val n=read.nextInt()
        if(n<1000)
        	println(n)
        else if(n>=1000 && n<1000000){
            val f=(n.toFloat())/1000
            if(f.roundToInt()<1000)
            println("" + f.roundToInt() + "K")
            else
            println("" + 1 + "M")
        }
        else{
            val f=(n.toFloat())/1000000
        	println(""+f.roundToInt()+"M")
        }
    }
}


import kotlin.math.roundToInt
import java.util.Scanner
fun main() {
    repeat(readLine()!!.toInt()){
        when(val n =readLine()!!.toInt()){
            in 0..999 -> println(n)
            in 1000..999_499 -> println("${(n+500)/1000}K")
            else -> println("${(n+500_000)/1_000_000}M")
        }
    }
}


/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */
import kotlin.math.roundToInt
import java.util.Scanner
fun main() {
    val read = Scanner(System.`in`)
    val t=read.nextInt()
    for(i in 1..t){
        val n=read.nextInt()
        if(n<1000)
        	println(n)
        else if(n>=1000 && n<1000000){
            val f=(n.toFloat())/1000
            if(f.roundToInt()<1000)
            println("" + f.roundToInt() + "K")
            else
            println("" + 1 + "M")
        }
        else{
            val f=(n.toFloat())/1000000
            println(f);
        	println(""+f.roundToInt()+"M")
        }
    }
}


import kotlin.math.roundToInt
import java.util.Scanner
fun main() {
    val read = Scanner(System.`in`)
    val t=read.nextInt()
    for(i in 1..t){
        val n=read.nextInt()
        if(n<1000)
        	println(n)
        else if(n>=1000 && n<1000000){
            val f=(n.toFloat())/1000.0
            println("" + f.roundToInt() + "K")
        }
        else{
            val f=(n.toFloat())/1000000.0
        	println(""+f.roundToInt()+"M")
        }
    }
}


/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */
import kotlin.math.roundToInt
import java.util.Scanner
fun main() {
    val read = Scanner(System.`in`)
    val t=read.nextInt()
    for(i in 1..t){
        val n=read.nextInt()
        if(n<1000)
        	println(n)
        else if(n>=1000 && n<1000000){
            val f=(n.toFloat())/1000.0
            if(f.roundToInt()<1000)
            println("" + f.roundToInt() + "K")
            else
            println("" + 1 + "M")
        }
        else{
            val f=(n.toFloat())/1000000.0
        	println(""+f.roundToInt()+"M")
        }
    }
}


import java.io.*
import java.util.*

fun min(a:Double,b:Double) = if (a<b) a else b

fun max(a:Double,b:Double) = if (a>b) a else b

fun min(a:Long,b:Long) = if (a<b) a else b

fun max(a:Long,b:Long) = if (a>b) a else b

var cin: BufferedReader? = null
var cout: PrintWriter? = null

var tok = StringTokenizer("")

fun init() {
    Locale.setDefault(Locale.US)
    cin = BufferedReader(InputStreamReader(System.`in`))
    cout = PrintWriter(System.`out`)
}

fun fode(n:Int) {
    if (n <= 999)
    {
        out.println((n).toString())
    }
    else if (n <= 999499)
    {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println((thousands).toString() + "K")
    }
    else
    {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println((millions).toString() + "M")
    }
}

fun powmod(a:Long,b:Long,mod:Long):Long {

    if (b==1.toLong()) return a;
    var k=powmod(a,b/2,mod);
    if (b%2==0.toLong())
    { return (k*k)%mod }
    else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }
}
fun prime (p:Long):Long {
    if (p==one) return 0.toLong();
    var i=two;
    while (i*i<=p) {if (p%i==nul) return i; i++; }
    return one;
}
fun inv (a:Long,mod:Long):Long {
return powmod(a,mod-2,mod);
}

fun readString(): String {
    while (!tok.hasMoreTokens()) {
        tok = StringTokenizer(cin!!.readLine())
    }
    return tok.nextToken()
}

fun readInt() = readString().toInt()

fun readIntArray(size: Int) = Array(size, { i -> readInt() })

fun readLong() = readString().toLong()
fun readLongArray(size: Long) = Array(size.toInt(), { i -> readLong() })
fun readLn():String = readLine()!!.toString()
fun readLongs()  = readLn().split(" ").map{it.toLong()}

fun solve() {

 /*
    var map=hashMapOf<String,Int>();
    map[q] <=> map.getOrDefault(q,0)
    Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));
    prLong("${k[i].second}"); - вывод аргумента пары
    var m=ArrayList<Long> (); <=> vector
    getline(cin,a) <=> readLine()!!.last()
   readLong() - одно число
   readLongs() - несколько чисел
   readLine()!!.toCharArray() - возвращает массив чаров из строки

    */
    /* --------- */
        // ВСЕГДА ПИСАТЬ В ЛОНГАХ
    var n = readInt();
    fode(n);

    /* --------- */

}

fun main() {
    init();
    val tests = readInt();
    for (i in o until tests) solve();
}


import java.io.*
import java.util.*

fun min(a:Double,b:Double) = if (a<b) a else b

fun max(a:Double,b:Double) = if (a>b) a else b

fun min(a:Long,b:Long) = if (a<b) a else b

fun max(a:Long,b:Long) = if (a>b) a else b

var cin: BufferedReader? = null
var cout: PrintWriter? = null

var tok = StringTokenizer("")

fun init() {
    Locale.setDefault(Locale.US)
    cin = BufferedReader(InputStreamReader(System.`in`))
    cout = PrintWriter(System.`out`)
}

fun fode(n:Int) {
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    if (n <= 999)
    {
        println((n).toString())
    }
    else if (n <= 999499)
    {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        println((thousands).toString() + "K")
    }
    else
    {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        println((millions).toString() + "M")
    }
}

fun powmod(a:Long,b:Long,mod:Long):Long {

    if (b==1.toLong()) return a;
    var k=powmod(a,b/2,mod);
    if (b%2==0.toLong())
    { return (k*k)%mod }
    else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }
}
fun prime (p:Long):Long {
    if (p==one) return 0.toLong();
    var i=two;
    while (i*i<=p) {if (p%i==nul) return i; i++; }
    return one;
}
fun inv (a:Long,mod:Long):Long {
return powmod(a,mod-2,mod);
}

fun readString(): String {
    while (!tok.hasMoreTokens()) {
        tok = StringTokenizer(cin!!.readLine())
    }
    return tok.nextToken()
}

fun readInt() = readString().toInt()

fun readIntArray(size: Int) = Array(size, { i -> readInt() })

fun readLong() = readString().toLong()
fun readLongArray(size: Long) = Array(size.toInt(), { i -> readLong() })
fun readLn():String = readLine()!!.toString()
fun readLongs()  = readLn().split(" ").map{it.toLong()}

fun solve() {

 /*
    var map=hashMapOf<String,Int>();
    map[q] <=> map.getOrDefault(q,0)
    Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));
    prLong("${k[i].second}"); - вывод аргумента пары
    var m=ArrayList<Long> (); <=> vector
    getline(cin,a) <=> readLine()!!.last()
   readLong() - одно число
   readLongs() - несколько чисел
   readLine()!!.toCharArray() - возвращает массив чаров из строки

    */
    /* --------- */
        // ВСЕГДА ПИСАТЬ В ЛОНГАХ
    var n = readInt();
    fode(n);

    /* --------- */

}

fun main() {
    init();
    val tests = readInt();
    for (i in o until tests) solve();
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Arrays
import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
object Main {
  @JvmStatic fun main(args:Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = TaskD()
    val test_cases = `in`.nextInt()
    for (i in 0 until test_cases) solver.solve(`in`, out)
    out.close()
  }
  internal class TaskD {
    private val n:Int = 0
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    fun solve(`in`:InputReader, out:PrintWriter) {
      n = `in`.nextInt()
      if (n <= 999)
      {
        out.println(n)
      }
      else if (n <= 999499)
      {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println(thousands + "K")
      }
      else
      {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println(millions + "M")
      }
    }
  }
  internal class InputReader(stream:InputStream) {
    var reader:BufferedReader
    var tokenizer:StringTokenizer
    init{
      reader = BufferedReader(InputStreamReader(stream), 32768)
      tokenizer = null
    }
    fun next():String {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
      {
        try
        {
          tokenizer = StringTokenizer(reader.readLine())
        }
        catch (e:IOException) {
          throw RuntimeException(e)
        }
      }
      return tokenizer.nextToken()
    }
    fun nextInt():Int {
      return Integer.parseInt(next())
    }
  }
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Arrays
import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
object Main {
  @JvmStatic fun main(args:Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = TaskD()
    val test_cases = `in`.nextInt()
    for (i in 0 until test_cases) solver.solve(`in`, out)
    out.close()
  }
  internal class TaskD {
    var n:Int = 0
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    fun solve(`in`:InputReader, out:PrintWriter) {
      n = `in`.nextInt()
      if (n <= 999)
      {
        out.println((n).toString())
      }
      else if (n <= 999499)
      {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println((thousands).toString() + "K")
      }
      else
      {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println((millions).toString() + "M")
      }
    }
  }
  internal class InputReader(stream:InputStream) {
    var reader:BufferedReader
    var tokenizer:StringTokenizer
    init{
      reader = BufferedReader(InputStreamReader(stream), 32768)
      tokenizer = StringTokenizer("")
    }
    fun next():String {
      while (!tokenizer.hasMoreTokens())
      {
        try
        {
          tokenizer = StringTokenizer(reader.readLine())
        }
        catch (e:IOException) {
          throw RuntimeException(e)
        }
      }
      return tokenizer.nextToken()
    }
    fun nextInt():Int {
      return Integer.parseInt(next())
    }
  }
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Arrays
import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
object Main {
  @JvmStatic fun main(args:Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = TaskD()
    val test_cases = `in`.nextInt()
    for (i in 0 until test_cases) solver.solve(`in`, out)
    out.close()
  }
  internal class TaskD {
    var n:Int = 0
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    fun solve(`in`:InputReader, out:PrintWriter) {
      n = `in`.nextInt()
      if (n <= 999)
      {
        out.println((n).toString())
      }
      else if (n <= 999499)
      {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println((thousands).toString() + "K")
      }
      else
      {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println((millions).toString() + "M")
      }
    }
  }
  internal class InputReader(stream:InputStream) {
    var reader:BufferedReader
    var tokenizer:StringTokenizer
    init{
      reader = BufferedReader(InputStreamReader(stream), 32768)
    }
    fun next():String {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
      {
        try
        {
          tokenizer = StringTokenizer(reader.readLine())
        }
        catch (e:IOException) {
          throw RuntimeException(e)
        }
      }
      return tokenizer.nextToken()
    }
    fun nextInt():Int {
      return Integer.parseInt(next())
    }
  }
}


import java.io.*
import java.util.*

fun min(a:Double,b:Double) = if (a<b) a else b

fun max(a:Double,b:Double) = if (a>b) a else b

fun min(a:Long,b:Long) = if (a<b) a else b

fun max(a:Long,b:Long) = if (a>b) a else b

var cin: BufferedReader? = null
var cout: PrintWriter? = null

var tok = StringTokenizer("")

fun init() {
    Locale.setDefault(Locale.US)
    cin = BufferedReader(InputStreamReader(System.`in`))
    cout = PrintWriter(System.`out`)
}

fun fode(n:Int) {
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    if (n <= 999)
    {
        println((n).toString())
    }
    else if (n <= 999499)
    {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        println((thousands).toString() + "K")
    }
    else
    {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        println((millions).toString() + "M")
    }
}

fun readString(): String {
    while (!tok.hasMoreTokens()) {
        tok = StringTokenizer(cin!!.readLine())
    }
    return tok.nextToken()
}

fun readInt() = readString().toInt()

fun readIntArray(size: Int) = Array(size, { i -> readInt() })

fun readLong() = readString().toLong()
fun readLongArray(size: Long) = Array(size.toInt(), { i -> readLong() })
fun readLn():String = readLine()!!.toString()
fun readLongs()  = readLn().split(" ").map{it.toLong()}

fun solve() {

 /*
    var map=hashMapOf<String,Int>();
    map[q] <=> map.getOrDefault(q,0)
    Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));
    prLong("${k[i].second}"); - вывод аргумента пары
    var m=ArrayList<Long> (); <=> vector
    getline(cin,a) <=> readLine()!!.last()
   readLong() - одно число
   readLongs() - несколько чисел
   readLine()!!.toCharArray() - возвращает массив чаров из строки

    */
    /* --------- */
        // ВСЕГДА ПИСАТЬ В ЛОНГАХ
    var n = readInt();
    fode(n);

    /* --------- */

}

fun main() {
    init();
    val tests = readInt();
    for (i in 0 until tests) solve();
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Arrays
import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
object Main {
  @JvmStatic fun main(args:Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = TaskD()
    val test_cases = `in`.nextInt()
    for (i in 0 until test_cases) solver.solve(`in`, out)
    out.close()
  }
  internal class TaskD {
    var n:Int = 0
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    fun solve(`in`:InputReader, out:PrintWriter) {
      n = `in`.nextInt()
      if (n <= 999)
      {
        out.println((n).toString())
      }
      else if (n <= 999499)
      {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println((thousands).toString() + "K")
      }
      else
      {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println((millions).toString() + "M")
      }
    }
  }
  internal class InputReader(stream:InputStream) {
    var reader:BufferedReader?
    var tokenizer:StringTokenizer?
    init{
      reader = BufferedReader(InputStreamReader(stream), 32768)
      tokenizer = null
    }
    fun next():String {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
      {
        try
        {
          tokenizer = StringTokenizer(reader.readLine())
        }
        catch (e:IOException) {
          throw RuntimeException(e)
        }
      }
      return tokenizer.nextToken()
    }
    fun nextInt():Int {
      return Integer.parseInt(next())
    }
  }
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Arrays
import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
object Main {
  @JvmStatic fun main(args:Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = TaskD()
    val test_cases = `in`.nextInt()
    for (i in 0 until test_cases) solver.solve(`in`, out)
    out.close()
  }
  internal class TaskD {
    var n:Int = 0
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    fun solve(`in`:InputReader, out:PrintWriter) {
      n = `in`.nextInt()
      if (n <= 999)
      {
        out.println((n).toString())
      }
      else if (n <= 999499)
      {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println((thousands).toString() + "K")
      }
      else
      {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println((millions).toString() + "M")
      }
    }
  }
  internal class InputReader(stream:InputStream) {
    var reader:BufferedReader
    var tokenizer:StringTokenizer
    init{
      reader = BufferedReader(InputStreamReader(stream), 32768)
      tokenizer = null
    }
    fun next():String {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
      {
        try
        {
          tokenizer = StringTokenizer(reader.readLine())
        }
        catch (e:IOException) {
          throw RuntimeException(e)
        }
      }
      return tokenizer.nextToken()
    }
    fun nextInt():Int {
      return Integer.parseInt(next())
    }
  }
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Arrays
import java.util.StringTokenizer
import java.io.BufferedReader
import java.io.InputStreamReader
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
object Main {
  @JvmStatic fun main(args:Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = InputReader(inputStream)
    val out = PrintWriter(outputStream)
    val solver = TaskD()
    val test_cases = `in`.nextInt()
    for (i in 0 until test_cases) solver.solve(`in`, out)
    out.close()
  }
  internal class TaskD {
    var n:Int = 0
    var thousands = 0
    var millions = 0
    var round1 = 0
    var round2 = 0
    fun solve(`in`:InputReader, out:PrintWriter) {
      n = `in`.nextInt()
      if (n <= 999)
      {
        out.println((n).toString())
      }
      else if (n <= 999499)
      {
        thousands = (n / 1000)
        round1 = (n % 1000)
        if (round1 >= 500) thousands += 1
        out.println((thousands).toString() + "K")
      }
      else
      {
        millions = (n / 1000000)
        round2 = (n % 1000000)
        if (round2 >= 500000) millions += 1
        out.println((millions).toString() + "M")
      }
    }
  }
  internal class InputReader(stream:InputStream) {
    var reader:BufferedReader
    var tokenizer:StringTokenizer
    init{
      reader = BufferedReader(InputStreamReader(stream), 32768)
      tokenizer = StringTokenizer("")
    }
    fun next():String {
      while (tokenizer == null || !tokenizer.hasMoreTokens())
      {
        try
        {
          tokenizer = StringTokenizer(reader.readLine())
        }
        catch (e:IOException) {
          throw RuntimeException(e)
        }
      }
      return tokenizer.nextToken()
    }
    fun nextInt():Int {
      return Integer.parseInt(next())
    }
  }
}


package kotlinheroes

fun main(){
    val n = readLine()!!.toInt()
    repeat(n) {
        val count = readLine()!!.toInt()
        when(count){
            in 1000001..9999999999 -> {
                if(count%1000000 >=500000) {
                    println("${(count/1000000)+1}M")
                }else{
                    println("${count/1000000}M")
                }
                return
            }
            999999 -> println("1M")
            in 1000..999998 -> {
                if(count%1000 >=500) {
                    println("${(count/1000)+1}K")
                }else{
                    println("${count/1000}K")
                }
                return
            }
            in 0..999 -> println(count)
        }
    }
}


package com.alexvanyo.contest.three

import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val n = readInt()

    repeat(n) {
        impl(readInt())
    }
}

fun impl(n: Int) {
    when {
        n < 1000 -> println(n)
        n < 999500 -> println("${round(n / 1000.0).toInt()}K")
        else -> println("${round(n / 1000000.0).toInt()}M")
    }
}


import kotlin.math.roundToInt

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {
    if (args.getOrNull(0) == "local") {
        System.setIn(object {}.javaClass.getResource("/contest/three/problem_a_1.txt").openStream())
    }

    repeat(readInt()) {
        impl(readInt())
    }
}

fun impl(n: Int) {
    when {
        n < 1000 -> println(n)
        n < 999500 -> println("${(n / 1000.0).roundToInt()}K")
        else -> println("${(n / 1000000.0).roundToInt()}M")
    }
}


package com.alexvanyo.contest.three

import kotlin.math.round

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {
    if (args.getOrNull(0) == "local") {
        System.setIn(object {}.javaClass.getResource("/contest/three/problem_a_1.txt").openStream())
    }

    val n = readInt()

    repeat(n) {
        impl(readInt())
    }
}

fun impl(n: Int) {
    when {
        n < 1000 -> println(n)
        n < 999500 -> println("${round(n / 1000.0).toInt()}K")
        else -> println("${round(n / 1000000.0).toInt()}M")
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kronos
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        long max(long a, long b) {
            return a > b ? a : b;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n - 1];
            long x = in.nextLong(), y;
            for (int i = 1; i < n; i++) {
                y = in.nextLong();
                if (i % 2 == 0) {
                    a[i - 1] = -Math.abs(x - y);
                } else {
                    a[i - 1] = Math.abs(x - y);
                }

                x = y;
            }
            long ans = a[0];
            long sum = 0;
            for (int i = 0; i < n - 1; i++) {
                sum += a[i];
                ans = max(ans, sum);
                sum = max(sum, 0);
                //a[i] += a[i-1];
            }
            out.println(ans);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kronos
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        long max(long a, long b) {
            return a > b ? a : b;
        }

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] a = new long[n - 1];
            long x = in.nextLong(), y;
            for (int i = 1; i < n; i++) {
                y = in.nextLong();
                if (i % 2 == 0) {
                    a[i - 1] = -Math.abs(x - y);
                } else {
                    a[i - 1] = Math.abs(x - y);
                }

                x = y;
            }
            long ans = a[0];
            long sum = 0;
            for (int i = 0; i < n - 1; i++) {
                sum += a[i];
                ans = max(ans, sum);
                sum = max(sum, 0);
                //a[i] += a[i-1];
            }
            sum = 0;
            for (int i = 1; i < n - 1; i++) {
                sum += -a[i];
                ans = max(ans, sum);
                sum = max(sum, 0);
                //a[i] += a[i-1];
            }
            out.println(ans);
        }

    }
}


import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        List<Integer> a=new ArrayList<Integer>();

        for(int i=0;i<n;i++){
            a.add(in.nextInt());
        }

        long[] f=new long[n];
        long[] f1=new long[n];

        long l=0,l1=0;

        f[0]=0;
        f1[0]=0;

        for(int i=1;i<n;i++){

          if(i%2==1)
              f[i]=min(f[i-1]+mod(a.get(i)-a.get(i-1)),mod(a.get(i)-a.get(i-1)));
           else
              f[i]=min(f[i-1]+(-1)*mod(a.get(i)-a.get(i-1)),(-1)*mod(a.get(i)-a.get(i-1)));

            if(i%2==1)
              f1[i]=max(f1[i-1]+mod(a.get(i)-a.get(i-1)),mod(a.get(i)-a.get(i-1)));
           else
              f1[i]=max(f1[i-1]+(-1)*mod(a.get(i)-a.get(i-1)),(-1)*mod(a.get(i)-a.get(i-1)));

            l=max(l,mod(f[i]));
            l1=max(l1,mod(f1[i]));
        }

        if(l>l1)
        System.out.print(l);
        else
            System.out.print(l1);
    }

    public static long max(long a,long b){
        if(a>b)
            return a;
        else
            return b;
    }

    public static long min(long a,long b){
        if(a<b)
            return a;
        else
            return b;
    }

    public static long mod(long a){
        if(a>0)
            return a;
        else
            return -a;
    }
}


import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        List<Integer> a=new ArrayList<Integer>();

        for(int i=0;i<n;i++){
            a.add(in.nextInt());
        }

        int[][] f=new int[n][n];
        int l=0;

        for(int i=0;i<n;i++){

            for(int j=i;j<n;j++){
                int k=j-i;

                if(i==0){
                    f[k][j]=0;
                }
                else if(i==1){
                    int g=a.get(k)-a.get(k+1);
                    if(j%2==0)
                        f[k][j]=mod(g);
                    else
                        f[k][j]=(-1)*mod(g);
                }
                else{

                    f[k][j]=f[k][j-1]+f[k+1][j]-f[k+1][j-1];
             //       System.out.println(f[k][j]);
                    }
         //      System.out.println(f[k][j]);
                l=max(mod(f[k][j]),l);
            }
        }

        System.out.print(l);
    }

    public static int max(int a,int b){
        if(a>b)
            return a;
        else
            return b;
    }

    public static int mod(int a){
        if(a>0)
            return a;
        else
            return -a;
    }
}


import java.util.*;

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        List<Integer> a=new ArrayList<Integer>();

        for(int i=0;i<n;i++){
            a.add(in.nextInt());
        }

        int[] f=new int[n];
        int l=0;

        f[0]=0;

        for(int i=1;i<n;i++){

          if(i%2==1)
              f[i]=max(f[i-1]+mod(a.get(i)-a.get(i-1)),mod(a.get(i)-a.get(i-1)));
           else
              f[i]=max(f[i-1]+(-1)*mod(a.get(i)-a.get(i-1)),(-1)*mod(a.get(i)-a.get(i-1)));

            l=max(l,mod(f[i]));
        }

        System.out.print(l);
    }

    public static int max(int a,int b){
        if(a>b)
            return a;
        else
            return b;
    }

    public static int mod(int a){
        if(a>0)
            return a;
        else
            return -a;
    }
}