without-statement-easy-contest
Source: hackerearth
Difficulty: HARD

Unfortunately someone has come and eaten the problem statement. Are you good enough to solve it without the statement?

Input
The first line contains T denoting the number of test cases.
The next  T lines describe test cases and contain two integers each: N and M.

Output
For each test case output one integer - answer for the question.

Constraints
T ≤ 1000
1 ≤ N, M ≤ 10^9

Note:
N, M ≤ 1000 for 30% of the test

SAMPLE INPUT
6
28 1
39 1
90 1
15 2
123 2
114514 1919

SAMPLE OUTPUT
68
90
81
40
17
16


up = [[0 for x in range(1000)] for y in range(30)]

def go(x):
	s = str(x)
	res = 0
	for i in s:
		res += int(i) * int(i)
	return res    

def make():
	global up
	for i in range(1000):
		up[0][i] = go(i)        
	for i in range(1, 30):
		for j in range(1000):
			up[i][j] = up[i-1][up[i-1][j]]


make()
for i in range(eval(input())):
	n, m = list(map(int, input().split()))
	n = go(n)
	m-=1
	for i in range(30):
		if (m & (1<<i)):
			n = up[i][n]
	print(n)        
	
			
			
			
			


for _ in range(int(input())):
	n, m = list(map(int, input().split()))
	arr = [sum([int(x)**2 for x in str(n)])]
	arrset = set(arr)
	for x in range(m - 1):
		arr.append(sum([int(x)**2 for x in str(arr[-1])]))
		if arr[-1] in arrset:
			# arr.pop()
			break
		arrset.add(arr[-1])
	else:
		print(arr[-1])
		continue
	narr, recur = [], None
	for x in range(len(arr) - 1):
		if arr[x] == arr[-1]:
			recur = arr[x:-1]
			break
		else:
			narr.append(arr[x])
	assert recur is not None
	if m <= len(narr):
		print(narr[m - 1])
	else:
		m -= len(narr) + 1
		print(recur[m % len(recur)])



#!/usr/bin/env python
#-*- coding:utf-8 -*-

import sys, math, random, operator
from string import ascii_lowercase
from string import ascii_uppercase
from fractions import Fraction, gcd
from decimal import Decimal, getcontext
from itertools import product, permutations, combinations
from queue import Queue, PriorityQueue
from collections import deque, defaultdict, Counter
getcontext().prec = 100

MOD = 10**9 + 7
INF = float("+inf")

if sys.subversion[0] != "CPython":  # PyPy?
	raw_input = lambda: sys.stdin.readline().rstrip()
pr = lambda *args: sys.stdout.write(" ".join(str(x) for x in args) + "\n")
epr = lambda *args: sys.stderr.write(" ".join(str(x) for x in args) + "\n")
die = lambda *args: pr(*args) ^ exit(0)

read_str = raw_input
read_strs = lambda: input().split()
read_int = lambda: int(input())
read_ints = lambda: list(map(int, input().split()))
read_float = lambda: float(input())
read_floats = lambda: list(map(float, input().split()))

"---------------------------------------------------------------"

cache = {}

def do(a):
	if a not in cache:
		ans = 0
		for d in map(int, str(a)):
			ans += d ** 2
		cache[a] = ans
		return ans
	return cache[a]

mod = 10**7
t = read_int()
for i in range(t):
	a, b = read_ints()
	cache = {}
	m = {a: 0}
	did = 0

	i = 0
	while i < b:
		# print "Q", i, a, "->", do(a)
		a = do(a)
		i += 1
		if not did and a in m:
			did = 1
			cyc = i - m[a]
			left = b - i
			left %= cyc
			# print a, m[a], b, i, left, cyc
			i = b - left
			# continue
		else:
			m[a] = i
	print(a)