There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.

Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378^{n}. 

 [Image] 

Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.


-----Input-----

The single line of input contains one integer n (0  ≤  n  ≤  10^9).


-----Output-----

Print single integer — the last digit of 1378^{n}.


-----Examples-----
Input
1

Output
8
Input
2

Output
4


-----Note-----

In the first example, last digit of 1378^1 = 1378 is 8.

In the second example, last digit of 1378^2 = 1378·1378 = 1898884 is 4.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Number theory

Implementation


Solutions:
import math

class Solution:

	def __init__(self):
		self.arr = [8, 4, 2, 6]

	def solution(self):
		n = int(input()) - 1
		if n == -1:
			print(1)
		else:
			for i in range(0, 5):
				if n % 4 == i:
					print(self.arr[i])
ob = Solution()
ob.solution()


n = int(input())
if n == 0:
	print('1')
else:
	ans = 8
	l = [1, 1, 4, 4, 2, 1, 1, 4, 4, 2]
	n = n % l[ans]
	if n == 0:
		n = l[ans]
	ans = ans ** n % 10
	print(ans)


n = int(input())
if n == 0:
	print('1')
elif n % 4 == 1:
	print('8')
elif n % 4 == 2:
	print('4')
elif n % 4 == 3:
	print('2')
else:
	print('6')


def cal(n):
	ans = [2, 6, 8, 4]
	n -= 3
	return ans[n % 4]
n = int(input())
if n == 0:
	print(1)
elif n == 1:
	print(8)
elif n == 2:
	print(4)
else:
	print(cal(n))


n = int(input())
if n == 0:
	x = 1
else:
	q = [6, 8, 4, 2]
	x = q[n % 4]
print(x)


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = ii()
lol = [8, 4, 2, 6]
if t == 0:
	print(1)
else:
	print(lol[(t - 1) % 4])


x = int(input())
if x == 0:
	print(1)
elif x % 4 == 1:
	print(8)
elif x % 4 == 2:
	print(4)
elif x % 4 == 3:
	print(2)
elif x % 4 == 0:
	print(6)


i = int(input())

def lastDigit(n):
	if n == 0:
		print(1)
	elif n % 4 == 0:
		print(6)
	elif n % 4 == 1:
		print(8)
	elif n % 4 == 2:
		print(4)
	else:
		print(2)
lastDigit(i)


n = int(input())
l = 3 * n
if n != 0:
	if n % 4 != 0:
		print(2 ** (l % 4))
	else:
		print(6)
else:
	print(1)


n = int(input())
m = 1378
print(pow(m, n, 10))


n = int(input())
ans = [8, 4, 2, 6]
if n is 0:
	print(1)
else:
	print(ans[(n - 1) % 4])


n = int(input())
if n == 0:
	print(1)
	exit()
num = n % 8
if num == 0:
	print(6)
else:
	num = 8 ** num
	num %= 10
	print(num)


n = int(input())
if n:
	print((8, 4, 2, 6)[(n - 1) % 4])
else:
	print(1)


a = int(input())
if a == 0:
	print(1)
else:
	b = a % 4
	if b == 0:
		print(6)
	elif b == 1:
		print(8)
	elif b == 2:
		print(4)
	elif b == 3:
		print(2)


def mod(n):
	if n == 0:
		return 1
	if n == 1:
		return 8
	t = mod(n // 2) % 10
	t = t * t % 10
	if n % 2:
		t = t * 8 % 10
	return t
print(mod(int(input())))


n = int(input())
while n - 512 > 0:
	n -= 512
while n - 32 > 0:
	n -= 32
while n - 4 > 0:
	n -= 4
if n == 0:
	print(1)
if n == 1:
	print(8)
if n == 2:
	print(4)
if n == 3:
	print(2)
if n == 4:
	print(6)


def main():
	n = int(input())
	if n == 0:
		print(1)
		return
	n2 = n % 100
	n1 = int(n2 / 10)
	n0 = n2 % 10
	if n1 % 2 == 0:
		l = [6, 8, 4, 2, 6, 8, 4, 2, 6, 8]
		print(l[n0])
	else:
		l = [4, 2, 6, 8, 4, 2, 6, 8, 4, 2]
		print(l[n0])
main()


n = int(input())
if n == 0:
	print('1')
elif n % 8 == 1 or n % 8 == 5:
	print('8')
elif n % 8 == 2 or n % 8 == 6:
	print('4')
elif n % 8 == 3 or n % 8 == 7:
	print('2')
elif n % 8 == 4 or n % 8 == 0:
	print('6')


N = int(input())
if N == 0:
	print(1)
	exit()
l = [8, 4, 2, 6]
n = (N - 1) % 4
print(l[n])


n = int(input())
d = {0: 6, 1: 8, 2: 4, 3: 2, 4: 6, 5: 8, 6: 4, 7: 2}
if n == 0:
	print('1')
else:
	print(d[n % 8])


n = int(input())
if n == 0:
	print(1)
else:
	mod = n % 4
	arr = (6, 8, 4, 2)
	print(arr[mod])


I = lambda : map(int, input().split())
n = int(input())
print(1 if n == 0 else (6, 8, 4, 2)[n % 4])


class Arpa:

	def __init__(self, number):
		self.number = number

	def calculate(self):
		print(pow(1378, int(self.number), 10))

def main():
	name = Arpa(int(input()))
	name.calculate()
main()


z = int(input())
if z == 0:
	print(1)
elif not z % 4:
	print(6)
elif z % 4 == 2:
	print(4)
elif z % 4 == 3:
	print(2)
else:
	print(8)


import sys
import queue
input = lambda : sys.stdin.readline()

def Main():
	n = int(input())
	d = [8, 4, 2, 6]
	x = d[n % 4 - 1]
	if n == 0:
		x = 1
	print(x)
Main()


n = int(input())
ans = '8426'
print(ans[(n - 1) % 4] if n else 1)


n = int(input())
if n == 0:
	print(1)
if n % 4 == 1:
	print(8)
if n % 4 == 2:
	print(4)
if n % 4 == 3:
	print(2)
if n % 4 == 0 and n != 0:
	print(6)


a = [6, 8, 4, 2]
n = int(input())
if n == 0:
	print(1)
else:
	print(a[n % 4])


n = int(input())
r = pow(1378, n, 10)
print(int(r))


n = int(input())
if n != 0 and n % 4 == 0:
	ans = str(8 ** 4)[-1]
else:
	ans = str(8 ** (n % 4))[-1]
print(ans)


def __starting_point():
	(n,) = map(int, input().split())
	if n == 0:
		print(1)
	elif n % 4 == 0:
		print(6)
	elif n % 4 == 1:
		print(8)
	elif n % 4 == 2:
		print(4)
	else:
		print(2)
__starting_point()


n = int(input())
ans = pow(1378, n, 10)
print(ans)


def pow(x, y, z):
	number = 1
	while y:
		if y & 1:
			number = number * x % z
		y >>= 1
		x = x * x % z
	return int(number)
a = int(input().strip())
print(pow(1378, a, 10))


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
n = ii()
a = [6, 8, 4, 2]
if n:
	ans = a[n % 4]
else:
	ans = 1
print(ans)


n = int(input())
z = int(n % 4)
if n == 0:
	print('1')
	exit()
if z == 0:
	print('6')
elif z == 1:
	print('8')
elif z == 2:
	print('4')
else:
	print('2')


n = int(input())
a = 8
result = 1
while n > 0:
	if n % 2:
		result = result % 10 * (a % 10) % 10
		n -= 1
	else:
		a = a % 10 * (a % 10) % 10
		n //= 2
print(result)


n = int(input())
a = '6842'
if n == 0:
	print('1')
else:
	print(a[n % 4])


x = int(input())
if x % 4 == 1:
	print(8)
if x % 4 == 2:
	print(4)
if x % 4 == 3:
	print(2)
if x % 4 == 0 and x != 0:
	print(6)
if x == 0:
	print(1)
c = 333333333
if c == 'rgergergher':
	print(8888888888)


def rints():
	return list(map(int, input().split()))

def ri():
	return int(input())
n = ri()
sol = {0: 6, 1: 8, 2: 4, 3: 2}
if n == 0:
	print(1)
else:
	print(sol[n % 4])


def main():
	print(pow(8, int(input()), 10))
main()


n = int(input())

def last(n):
	if n == 0:
		return 1
	k = n % 4
	if k == 0:
		return 6
	if k == 1:
		return 8
	if k == 2:
		return 4
	if k == 3:
		return 2
print(last(n))


n = int(input())
var = pow(1378, n, 10)
print(var)


n = int(input())
if n == 0:
	print(1)
else:
	t = n % 4
	if t == 0:
		t = 4
	print(8 ** t % 10)


import sys

def main(n):
	if n == 0:
		return 1
	d = {1: 8, 2: 4, 3: 2, 0: 6}
	return d[n % 4]
for (e, line) in enumerate(sys.stdin.readlines()):
	n = int(line.strip())
print(main(n))


import math
n = int(input())
x = n % 4
if n == 0:
	x = 0
elif x == 0:
	x = 4
print(int(math.pow(8, x)) % 10)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	return pow(1378, n, 10)
print(main())


n = int(input())
if n == 0:
	answer = 1
else:
	mod = n % 4
	if mod == 0:
		answer = 6
	elif mod == 1:
		answer = 8
	elif mod == 2:
		answer = 4
	else:
		answer = 2
print(answer)


def fastexp(x, n, m):
	result = 1
	currentpower = x
	while n > 0:
		if n % 2 == 1:
			result = result * currentpower % m
		currentpower = currentpower * currentpower % m
		n = n // 2
	return result
a = int(input())
b = fastexp(8, a, 10)
print(b)


print(pow(1378, int(input()), 10))


n = int(input())
ld = [8, 4, 2, 6]
print(ld[n % 4 - 1] if n is not 0 else 1)


def fast_pow(a, n, mod):
	if n == 0:
		return 1
	elif n == 1:
		return a % mod
	h = fast_pow(a, n // 2, mod)
	if n % 2 == 0:
		return h * h % mod
	return h * h * a % mod
n = int(input())
print(fast_pow(1378, n, 10))


n = int(input())
a = pow(8, n, 10)
print(a)


n = int(input())
no = n % 4
if n == 0:
	print('1')
elif no == 0:
	print(1378 ** 4 % 10)
else:
	print(1378 ** no % 10)


tobeprinted = [8, 4, 2, 6]
N = int(input())
if N == 0:
	print('1')
else:
	print(tobeprinted[N % 4 - 1])


a = int(input())
if a == 0:
	print('1')
if a > 0:
	b = [8, 4, 2, 6]
	a = (a - 1) % 4
	print(b[a])


n = int(input())
c = [6, 8, 4, 2]
if n == 0:
	print(1)
else:
	k = n % 4
	print(c[k])


inp = int(input())
ans = pow(1378, inp, 10)
print(ans)


a = int(input())
if a == 0:
	print(1)
	exit(0)
a %= 4
if a == 0:
	print(6)
elif a == 1:
	print(8)
elif a == 2:
	print(4)
elif a == 3:
	print(2)


n = int(input())
if n != 0 and n % 4 == 0:
	n = 4
elif n != 0:
	n %= 4
print(8 ** n % 10)


t = int(input())
if t == 0:
	print(1)
else:
	z = t % 4
	i = 1
	if z == 0:
		print(6)
	elif z == 2:
		print(4)
	elif z == 3:
		print(2)
	else:
		print(8)


def power(a, b, mod):
	res = 1
	while b:
		if b % 2:
			res = res * a % mod
			b -= 1
		else:
			a = a * a % mod
			b = b // 2
	return res

def main():
	n = int(input())
	print(power(8, n, 10))
main()


import sys
n = int(input())
if n == 0:
	print(1)
	sys.exit(0)
if n % 4 == 0:
	print(6)
elif n % 4 == 1:
	print(8)
elif n % 4 == 2:
	print(4)
else:
	print(2)


import math
from fractions import Fraction as frac
MOD = 1000000000.0 + 7

def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def solve(case_no):
	n = int(input())
	if n == 0:
		print(1)
		exit()
	n %= 4
	if n == 1:
		print(8)
	elif n == 2:
		print(4)
	elif n == 3:
		print(2)
	else:
		print(6)
t = 1
for i in range(1, t + 1):
	solve(i)


i = int(input())
n = 1
if i != 0:
	i = i % 4 + 4
	while i > 0:
		i -= 1
		n *= 8
		n = n % 10
print(n)


import math
n = int(input())
print(pow(1378, n, 10))


n = int(input())
if not n:
	print(1)
else:
	abc = [8, 4, 2, 6]
	print(abc[(n - 1) % 4])


n = int(input())
print([6, 8, 4, 2, 1][n % 4 - (n == 0)])


def exponent(x, n, m):
	if n == 0:
		return 1
	elif n % 2 == 0:
		return exponent(x * x % m, n / 2, m)
	elif n % 2 != 0:
		return x * exponent(x * x % m, (n - 1) / 2, m) % m
n = int(input())
c = exponent(8, n, 100)
print(c % 10)


print(pow(8, int(input()), 10))


a = int(input())
print(int(int(a % 4 == 1) * 8 + int(a % 4 == 2) * 4 + int(a % 4 == 3) * 2 + int(a % 4 == 0) * 6) * int(a != 0) + 1 * int(a == 0))


n = int(input())
if n == 0:
	print('1')
else:
	n -= 1
	s = '8426'
	print(s[n % 4])


import sys
n = int(sys.stdin.readline())
a = 1378
endVals = [8, 4, 2, 6]
if n != 0:
	print(endVals[n % 4 - 1])
else:
	print(1)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
n = sInt()
if n == 0:
	print(1)
elif n - n // 4 * 4 == 1:
	print(8)
elif n - n // 4 * 4 == 2:
	print(4)
elif n - n // 4 * 4 == 3:
	print(2)
elif n % 4 == 0:
	print(6)


def res(n):
	if n == 0:
		return 1
	n %= 4
	if n == 1:
		return 8
	if n == 2:
		return 4
	if n == 3:
		return 2
	if n == 0:
		return 6
n = int(input())
print(res(n))


n = int(input())
if n == 0:
	print('1')
else:
	n = n % 4
	if n == 0:
		n = 4
	s = 8 ** n
	print(s % 10)


def rb(n, a):
	res = 1
	while a:
		if a % 2:
			res = res * n % 10
			a = a - 1
		else:
			n = n * n % 10
			a = a // 2
	return res
a = int(input())
t = 8
print(rb(8, a) % 10)


def power(n):
	res = 1
	if n <= 1:
		return 8 ** n
	if n % 2 == 0:
		z = power(n // 2) % 10
		return z * z % 10
	else:
		return 8 * power(n - 1)
n = int(input())
print(power(n) % 10)


def force(a, n):
	a %= 10
	if n == 0:
		return 1
	if n % 2 == 1:
		return force(a, n - 1) * a % 10
	return force(a * a, n // 2)
x = int(input())
print(force(1378, x) % 10)


i = int(input())
if i == 0:
	print(1)
else:
	print([8, 4, 2, 6][(i - 1) % 4])


n = int(input())
res = [6, 8, 4, 2, 1]
rem = n % 4
if n == 0:
	print(res[4])
else:
	print(res[rem])


n = int(input())
ans = 1
a = 8
while n > 0:
	if n % 2 == 1:
		ans = ans % 10 * (a % 10) % 10
		n -= 1
	a = a % 10 * (a % 10) % 10
	n //= 2
print(ans)


a = 8
b = int(input())
print(pow(8, b, 10))


n = int(input())
print(1 if n == 0 else 2 ** (4 - n % 4) if n % 4 != 0 else 6)


n = int(input())

def power(x, n, mod):
	ans = 1
	while n > 0:
		if n & 1:
			ans = ans * x % mod
			n -= 1
		else:
			x = x * x % mod
			n //= 2
	return ans
print(power(8, n, 10))


from sys import stdin, stdout
ds = [6, 8, 4, 2]
n = int(stdin.readline())
stdout.write(('1' if n == 0 else str(ds[n % 4])) + '\n')


n = int(input())
i = str(pow(8, n, 10))
print(i[-1])


import math
a = int(input())
b = 1378
p = 1
while a > 0:
	if a % 2 == 1:
		p = p * b % 10
	b = b * b % 10
	a = int(a / 2)
print(p % 10)


import math
from queue import LifoQueue

def inp():
	return int(input().strip())

def inlist():
	return list(map(int, input().strip().split()))

def instr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().strip().split())
n = inp()
c = pow(2, 3 * n, 10)
print(c % 10)


import math
from bisect import bisect_right as br
import sys
input = sys.stdin.readline
n = int(input())
if n == 0:
	print(1)
else:
	x = [6, 8, 4, 2]
	c = n % 4
	print(x[c])


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
if t == 0:
	print(1)
else:
	dep = t % 4
	if dep == 0:
		print(6)
	if dep == 1:
		print(8)
	if dep == 3:
		print(2)
	if dep == 2:
		print(4)


def lastdigit(t):
	if t == 0:
		return '6'
	if t == 1:
		return '8'
	if t == 2:
		return '4'
	if t == 3:
		return '2'
t = int(input())
if t != 0:
	t = t % 4
	print(lastdigit(t))
else:
	print('1')


n = int(input())
if n == 0:
	print(1)
	exit()
n = n % 4
s = '8426'
print(s[n - 1])


import sys
n = int(sys.stdin.readline().rstrip())
if n == 0:
	print(1)
else:
	m = 10

	def ex(v, x):
		if x == 1:
			return v
		if x % 2 == 0:
			trick = ex(v, x / 2) % m
			return trick * trick % m
		return ex(v, x - 1) * v % m
	print(ex(2, n) % m * ex(3, n) % m * ex(3, n) % m % m)


n = int(input())
ref = int(n % 4)
if n == 0:
	print(1)
else:
	if n == 1 or ref - 1 == 0:
		print(8)
	if n == 2 or ref - 2 == 0:
		print(4)
	if n == 3 or ref - 3 == 0:
		print(2)
	if n == 4 or ref == 0:
		print(6)


from sys import stdin
from sys import stdout
x = int(stdin.readline().strip())
ans = [6, 8, 4, 2]
if x == 0:
	stdout.write(str(1))
else:
	stdout.write(str(ans[x % 4]))


li = [1, 8, 4, 2, 6, 8]
x = int(input())
if x < 1:
	print(1378 ** x % 10)
else:
	i = 1 + (4 + x % 4 - 1 % 4) % 4
	print(1378 ** i % 10)


from sys import stdin as AccordingtoallknownlawsofaviationthereisnowayabeeshouldbeabletoflyItswingsaretoosmalltogetitsfatlittlebodyoffthegroundThebeeofcoursefliesanywaybecausebeesdontcarewhathumansthinkisimpossibleYellowblackYellowblackYellowblackYellowblackOohblackandyellowLetsshakeitupalittleBarryBreakfastisreadyOomingHangonasecondHelloBarryAdamOanyoubelievethisishappeningIcantIllpickyouupLookingsharpUsethestairsYourfatherpaidgoodmoneyforthoseSorryImexcitedHeresthegraduateWereveryproudofyousonAperfectreportcardallBsVeryproudMaIgotathinggoinghereYougotlintonyourfuzzOwThatsmeWavetousWellbeinrow118000ByeBarryItoldyoustopflyinginthehouseHeyAdamHeyBarryIsthatfuzzgelAlittleSpecialdaygraduationNeverthoughtIdmakeitThreedaysgradeschoolthreedayshighschoolThosewereawkwardThreedayscollegeImgladItookadayandhitchhikedaroundthehiveYoudidcomebackdifferentHiBarryArtiegrowingamustacheLooksgoodHearaboutFrankieYeahYougoingtothefuneralNoImnotgoingEverybodyknowsstingsomeoneyoudieDontwasteitonasquirrelSuchahotheadIguesshecouldhavejustgottenoutofthewayIlovethisincorporatinganamusementparkintoourdayThatswhywedontneedvacationsBoyquiteabitofpompunderthecircumstancesWellAdamtodaywearemenWeareBeemenAmenHallelujahStudentsfacultydistinguishedbeespleasewelcomeDeanBuzzwellWelcomeNewHiveOitygraduatingclassof915ThatconcludesourceremoniesAndbeginsyourcareeratHonexIndustriesWillwepickourjobtodayIhearditsjustorientationHeadsupHerewegoKeepyourhandsandantennasinsidethetramatalltimesWonderwhatitllbelikeAlittlescaryWelcometoHonexadivisionofHonescoandapartoftheHexagonGroupThisisitWowWowWeknowthatyouasabeehaveworkedyourwholelifetogettothepointwhereyoucanworkforyourwholelifeHoneybeginswhenourvaliantPollenJocksbringthenectartothehiveOurtopsecretformulaisautomaticallycolorcorrectedscentadjustedandbubblecontouredintothissoothingsweetsyrupwithitsdistinctivegoldenglowyouknowasHoneyThatgirlwashotShesmycousinSheisYeswereallcousinsRightYourerightAtHonexweconstantlystrivetoimproveeveryaspectofbeeexistenceThesebeesarestresstestinganewhelmettechnologyWhatdoyouthinkhemakesNotenoughHerewehaveourlatestadvancementtheKrelmanWhatdoesthatdoOatchesthatlittlestrandofhoneythathangsafteryoupouritSavesusmillionsOananyoneworkontheKrelmanOfcourseMostbeejobsaresmallonesButbeesknowthateverysmalljobifitsdonewellmeansalotButchoosecarefullybecauseyoullstayinthejobyoupickfortherestofyourlifeThesamejobtherestofyourlifeIdidntknowthatWhatsthedifferenceYoullbehappytoknowthatbeesasaspecieshaventhadonedayoffin27millionyearsSoyoulljustworkustodeathWellsuretryWowThatblewmymindWhatsthedifferenceHowcanyousaythatOnejobforeverThatsaninsanechoicetohavetomakeImrelievedNowweonlyhavetomakeonedecisioninlifeButAdamhowcouldtheyneverhavetoldusthatWhywouldyouquestionanythingWerebeesWerethemostperfectlyfunctioningsocietyonEarthYoueverthinkmaybethingsworkalittletoowellhereLikewhatGivemeoneexampleIdontknowButyouknowwhatImtalkingaboutPleaseclearthegateRoyalNectarForceonapproachWaitasecondOheckitoutHeythosearePollenJocksWowIveneverseenthemthiscloseTheyknowwhatitslikeoutsidethehiveYeahbutsomedontcomebackHeyJocksHiJocksYouguysdidgreatYouremonstersYoureskyfreaksIloveitIloveitIwonderwheretheywereIdontknowTheirdaysnotplannedOutsidethehiveflyingwhoknowswheredoingwhoknowswhatYoucantjustdecidetobeaPollenJockYouhavetobebredforthatRightLookThatsmorepollenthanyouandIwillseeinalifetimeItsjustastatussymbolBeesmaketoomuchofitPerhapsUnlessyourewearingitandtheladiesseeyouwearingitThoseladiesArenttheyourcousinstooDistantDistantLookatthesetwoOoupleofHiveHarrysLetshavefunwiththemItmustbedangerousbeingaPollenJockYeahOnceabearpinnedmeagainstamushroomHehadapawonmythroatandwiththeotherhewasslappingmeOhmyIneverthoughtIdknockhimoutWhatwereyoudoingduringthisTryingtoalerttheauthoritiesIcanautographthatAlittlegustyouttheretodaywasntitcomradesYeahGustyWerehittingasunflowerpatchsixmilesfromheretomorrowSixmileshuhBarryApuddlejumpforusbutmaybeyourenotupforitMaybeIamYouarenotWeregoing0900atJGateWhatdoyouthinkbuzzyboyAreyoubeeenoughImightbeItalldependsonwhat0900meansHeyHonexDadyousurprisedmeYoudecidewhatyoureinterestedinWelltheresalotofchoicesButyouonlygetoneDoyouevergetboreddoingthesamejobeverydaySonletmetellyouaboutstirringYougrabthatstickandyoujustmoveitaroundandyoustiritaroundYougetyourselfintoarhythmItsabeautifulthingYouknowDadthemoreIthinkaboutitmaybethehoneyfieldjustisntrightformeYouwerethinkingofwhatmakingballoonanimalsThatsabadjobforaguywithastingerJanetyoursonsnotsurehewantstogointohoneyBarryyouaresofunnysometimesImnottryingtobefunnyYourenotfunnyYouregoingintohoneyOursonthestirrerYouregonnabeastirrerNooneslisteningtomeWaittillyouseethesticksIhaveIcouldsayanythingrightnowImgonnagetananttattooLetsopensomehoneyandcelebrateMaybeIllpiercemythoraxShavemyantennaeShackupwithagrasshopperGetagoldtoothandcalleverybodydawgImsoproudWerestartingworktodayTodaysthedayOomeonAllthegoodjobswillbegoneYeahrightPollencountingstuntbeepouringstirrerfrontdeskhairremovalIsitstillavailableHangonTwoleftOneofthemsyoursOongratulationsSteptothesideWhatdyougetPickingcrudoutStellarWowOoupleofnewbiesYessirOurfirstdayWearereadyMakeyourchoiceYouwanttogofirstNoyougoOhmyWhatsavailableRestroomattendantsopennotforthereasonyouthinkAnychanceofgettingtheKrelmanSureyoureonImsorrytheKrelmanjustclosedoutWaxmonkeysalwaysopenTheKrelmanopenedupagainWhathappenedAbeediedMakesanopeningSeeHesdeadAnotherdeadoneDeadyDeadifiedTwomoredeadDeadfromtheneckupDeadfromtheneckdownThatslifeOhthisissohardHeatingcoolingstuntbeepourerstirrerhumminginspectornumbersevenlintcoordinatorstripesupervisormitewranglerBarrywhatdoyouthinkIshouldBarryBarryAllrightwevegotthesunflowerpatchinquadrantnineWhathappenedtoyouWhereareyouImgoingoutOutOutwhereOutthereOhnoIhavetobeforeIgotoworkfortherestofmylifeYouregonnadieYourecrazyHelloAnothercallcominginIfanyonesfeelingbravetheresaKoreandelion83rdthatgetstheirrosestodayHeyguysLookatthatIsntthatthekidwesawyesterdayHolditsonflightdecksrestrictedItsOKLouWeregonnatakehimupReallyFeelingluckyareyouSignherehereJustinitialthatThankyouOKYougotarainadvisorytodayandasyouallknowbeescannotflyinrainSobecarefulAsalwayswatchyourbroomshockeysticksdogsbirdsbearsandbatsAlsoIgotacoupleofreportsofrootbeerbeingpouredonusMurphysinahomebecauseofitbabblinglikeacicadaThatsawfulAndareminderforyourookiesbeelawnumberoneabsolutelynotalkingtohumansAllrightlaunchpositionsBuzzbuzzbuzzbuzzBuzzbuzzbuzzbuzzBuzzbuzzbuzzbuzzBlackandyellowHelloYoureadyforthishotshotYeahYeahbringitonWindcheckAntennaecheckNectarpackcheckWingscheckStingercheckScaredoutofmyshortscheckOKladiesletsmoveitoutPoundthosepetuniasyoustripedstemsuckersAllofyoudrainthoseflowersWowImoutIcantbelieveImoutSoblueIfeelsofastandfreeBoxkiteWowFlowersThisisBlueLeaderWehaverosesvisualBringitaround30degreesandholdRoses30degreesrogerBringingitaroundStandtothesidekidItsgotabitofakickThatisonenectarcollectorEverseepollinationupcloseNosirIpickupsomepollenheresprinkleitoverhereMaybeadashoverthereapinchonthatoneSeethatItsalittlebitofmagicThatsamazingWhydowedothatThatspollenpowerMorepollenmoreflowersmorenectarmorehoneyforusOoolImpickingupalotofbrightyellowOouldbedaisiesDontweneedthoseOopythatvisualWaitOneoftheseflowersseemstobeonthemoveSayagainYourereportingamovingflowerAffirmativeThatwasonthelineThisisthecoolestWhatisitIdontknowbutImlovingthiscolorItsmellsgoodNotlikeaflowerbutIlikeitYeahfuzzyOhemicalyOarefulguysItsalittlegrabbyMysweetlordofbeesOandybraingetoffthereProblemGuysThiscouldb
n = int(AccordingtoallknownlawsofaviationthereisnowayabeeshouldbeabletoflyItswingsaretoosmalltogetitsfatlittlebodyoffthegroundThebeeofcoursefliesanywaybecausebeesdontcarewhathumansthinkisimpossibleYellowblackYellowblackYellowblackYellowblackOohblackandyellowLetsshakeitupalittleBarryBreakfastisreadyOomingHangonasecondHelloBarryAdamOanyoubelievethisishappeningIcantIllpickyouupLookingsharpUsethestairsYourfatherpaidgoodmoneyforthoseSorryImexcitedHeresthegraduateWereveryproudofyousonAperfectreportcardallBsVeryproudMaIgotathinggoinghereYougotlintonyourfuzzOwThatsmeWavetousWellbeinrow118000ByeBarryItoldyoustopflyinginthehouseHeyAdamHeyBarryIsthatfuzzgelAlittleSpecialdaygraduationNeverthoughtIdmakeitThreedaysgradeschoolthreedayshighschoolThosewereawkwardThreedayscollegeImgladItookadayandhitchhikedaroundthehiveYoudidcomebackdifferentHiBarryArtiegrowingamustacheLooksgoodHearaboutFrankieYeahYougoingtothefuneralNoImnotgoingEverybodyknowsstingsomeoneyoudieDontwasteitonasquirrelSuchahotheadIguesshecouldhavejustgottenoutofthewayIlovethisincorporatinganamusementparkintoourdayThatswhywedontneedvacationsBoyquiteabitofpompunderthecircumstancesWellAdamtodaywearemenWeareBeemenAmenHallelujahStudentsfacultydistinguishedbeespleasewelcomeDeanBuzzwellWelcomeNewHiveOitygraduatingclassof915ThatconcludesourceremoniesAndbeginsyourcareeratHonexIndustriesWillwepickourjobtodayIhearditsjustorientationHeadsupHerewegoKeepyourhandsandantennasinsidethetramatalltimesWonderwhatitllbelikeAlittlescaryWelcometoHonexadivisionofHonescoandapartoftheHexagonGroupThisisitWowWowWeknowthatyouasabeehaveworkedyourwholelifetogettothepointwhereyoucanworkforyourwholelifeHoneybeginswhenourvaliantPollenJocksbringthenectartothehiveOurtopsecretformulaisautomaticallycolorcorrectedscentadjustedandbubblecontouredintothissoothingsweetsyrupwithitsdistinctivegoldenglowyouknowasHoneyThatgirlwashotShesmycousinSheisYeswereallcousinsRightYourerightAtHonexweconstantlystrivetoimproveeveryaspectofbeeexistenceThesebeesarestresstestinganewhelmettechnologyWhatdoyouthinkhemakesNotenoughHerewehaveourlatestadvancementtheKrelmanWhatdoesthatdoOatchesthatlittlestrandofhoneythathangsafteryoupouritSavesusmillionsOananyoneworkontheKrelmanOfcourseMostbeejobsaresmallonesButbeesknowthateverysmalljobifitsdonewellmeansalotButchoosecarefullybecauseyoullstayinthejobyoupickfortherestofyourlifeThesamejobtherestofyourlifeIdidntknowthatWhatsthedifferenceYoullbehappytoknowthatbeesasaspecieshaventhadonedayoffin27millionyearsSoyoulljustworkustodeathWellsuretryWowThatblewmymindWhatsthedifferenceHowcanyousaythatOnejobforeverThatsaninsanechoicetohavetomakeImrelievedNowweonlyhavetomakeonedecisioninlifeButAdamhowcouldtheyneverhavetoldusthatWhywouldyouquestionanythingWerebeesWerethemostperfectlyfunctioningsocietyonEarthYoueverthinkmaybethingsworkalittletoowellhereLikewhatGivemeoneexampleIdontknowButyouknowwhatImtalkingaboutPleaseclearthegateRoyalNectarForceonapproachWaitasecondOheckitoutHeythosearePollenJocksWowIveneverseenthemthiscloseTheyknowwhatitslikeoutsidethehiveYeahbutsomedontcomebackHeyJocksHiJocksYouguysdidgreatYouremonstersYoureskyfreaksIloveitIloveitIwonderwheretheywereIdontknowTheirdaysnotplannedOutsidethehiveflyingwhoknowswheredoingwhoknowswhatYoucantjustdecidetobeaPollenJockYouhavetobebredforthatRightLookThatsmorepollenthanyouandIwillseeinalifetimeItsjustastatussymbolBeesmaketoomuchofitPerhapsUnlessyourewearingitandtheladiesseeyouwearingitThoseladiesArenttheyourcousinstooDistantDistantLookatthesetwoOoupleofHiveHarrysLetshavefunwiththemItmustbedangerousbeingaPollenJockYeahOnceabearpinnedmeagainstamushroomHehadapawonmythroatandwiththeotherhewasslappingmeOhmyIneverthoughtIdknockhimoutWhatwereyoudoingduringthisTryingtoalerttheauthoritiesIcanautographthatAlittlegustyouttheretodaywasntitcomradesYeahGustyWerehittingasunflowerpatchsixmilesfromheretomorrowSixmileshuhBarryApuddlejumpforusbutmaybeyourenotupforitMaybeIamYouarenotWeregoing0900atJGateWhatdoyouthinkbuzzyboyAreyoubeeenoughImightbeItalldependsonwhat0900meansHeyHonexDadyousurprisedmeYoudecidewhatyoureinterestedinWelltheresalotofchoicesButyouonlygetoneDoyouevergetboreddoingthesamejobeverydaySonletmetellyouaboutstirringYougrabthatstickandyoujustmoveitaroundandyoustiritaroundYougetyourselfintoarhythmItsabeautifulthingYouknowDadthemoreIthinkaboutitmaybethehoneyfieldjustisntrightformeYouwerethinkingofwhatmakingballoonanimalsThatsabadjobforaguywithastingerJanetyoursonsnotsurehewantstogointohoneyBarryyouaresofunnysometimesImnottryingtobefunnyYourenotfunnyYouregoingintohoneyOursonthestirrerYouregonnabeastirrerNooneslisteningtomeWaittillyouseethesticksIhaveIcouldsayanythingrightnowImgonnagetananttattooLetsopensomehoneyandcelebrateMaybeIllpiercemythoraxShavemyantennaeShackupwithagrasshopperGetagoldtoothandcalleverybodydawgImsoproudWerestartingworktodayTodaysthedayOomeonAllthegoodjobswillbegoneYeahrightPollencountingstuntbeepouringstirrerfrontdeskhairremovalIsitstillavailableHangonTwoleftOneofthemsyoursOongratulationsSteptothesideWhatdyougetPickingcrudoutStellarWowOoupleofnewbiesYessirOurfirstdayWearereadyMakeyourchoiceYouwanttogofirstNoyougoOhmyWhatsavailableRestroomattendantsopennotforthereasonyouthinkAnychanceofgettingtheKrelmanSureyoureonImsorrytheKrelmanjustclosedoutWaxmonkeysalwaysopenTheKrelmanopenedupagainWhathappenedAbeediedMakesanopeningSeeHesdeadAnotherdeadoneDeadyDeadifiedTwomoredeadDeadfromtheneckupDeadfromtheneckdownThatslifeOhthisissohardHeatingcoolingstuntbeepourerstirrerhumminginspectornumbersevenlintcoordinatorstripesupervisormitewranglerBarrywhatdoyouthinkIshouldBarryBarryAllrightwevegotthesunflowerpatchinquadrantnineWhathappenedtoyouWhereareyouImgoingoutOutOutwhereOutthereOhnoIhavetobeforeIgotoworkfortherestofmylifeYouregonnadieYourecrazyHelloAnothercallcominginIfanyonesfeelingbravetheresaKoreandelion83rdthatgetstheirrosestodayHeyguysLookatthatIsntthatthekidwesawyesterdayHolditsonflightdecksrestrictedItsOKLouWeregonnatakehimupReallyFeelingluckyareyouSignherehereJustinitialthatThankyouOKYougotarainadvisorytodayandasyouallknowbeescannotflyinrainSobecarefulAsalwayswatchyourbroomshockeysticksdogsbirdsbearsandbatsAlsoIgotacoupleofreportsofrootbeerbeingpouredonusMurphysinahomebecauseofitbabblinglikeacicadaThatsawfulAndareminderforyourookiesbeelawnumberoneabsolutelynotalkingtohumansAllrightlaunchpositionsBuzzbuzzbuzzbuzzBuzzbuzzbuzzbuzzBuzzbuzzbuzzbuzzBlackandyellowHelloYoureadyforthishotshotYeahYeahbringitonWindcheckAntennaecheckNectarpackcheckWingscheckStingercheckScaredoutofmyshortscheckOKladiesletsmoveitoutPoundthosepetuniasyoustripedstemsuckersAllofyoudrainthoseflowersWowImoutIcantbelieveImoutSoblueIfeelsofastandfreeBoxkiteWowFlowersThisisBlueLeaderWehaverosesvisualBringitaround30degreesandholdRoses30degreesrogerBringingitaroundStandtothesidekidItsgotabitofakickThatisonenectarcollectorEverseepollinationupcloseNosirIpickupsomepollenheresprinkleitoverhereMaybeadashoverthereapinchonthatoneSeethatItsalittlebitofmagicThatsamazingWhydowedothatThatspollenpowerMorepollenmoreflowersmorenectarmorehoneyforusOoolImpickingupalotofbrightyellowOouldbedaisiesDontweneedthoseOopythatvisualWaitOneoftheseflowersseemstobeonthemoveSayagainYourereportingamovingflowerAffirmativeThatwasonthelineThisisthecoolestWhatisitIdontknowbutImlovingthiscolorItsmellsgoodNotlikeaflowerbutIlikeitYeahfuzzyOhemicalyOarefulguysItsalittlegrabbyMysweetlordofbeesOandybraingetoffthereProblemGuysThiscouldb.readline())
if n != 0:
	print([8, 4, 2, 6][n % 4 - 1])
else:
	print(1)


t = int(input())
a = [8, 4, 2, 6]
print(a[t % 4 - 1] if t >= 1 else 1)


p = int(input())

def x(p):
	if p == 0:
		return 1
	return [6, 8, 4, 2][p % 4]
print(x(p))


def f(x, p):
	if p == 0:
		return 1
	elif p % 2 == 1:
		return x * f(x, p - 1) % 10
	else:
		return f(x, p / 2) ** 2 % 10
print(f(1378, int(input())))


import sys
import math
sz = int(input())
if sz == 0:
	print(1)
	exit(0)
s = str(8 ** ((sz - 1) % 4 + 1))
print(s[len(s) - 1])


def countMaxSetBits(left, right):
	while left | left + 1 <= right:
		left |= left + 1
	return left
n = int(input())
var = n % 4
if n == 0:
	print(1)
	exit()
if var == 0:
	print(6)
if var == 1:
	print(8)
if var == 2:
	print(4)
if var == 3:
	print(2)


import math
x = int(input())
if x == 0:
	print(1)
	exit()
x = x % 4
if x == 0:
	x = 4
print(pow(1378, x) % 10)


def ans(n):
	if n == 0:
		return 1
	return [6, 8, 4, 2][n % 4]
n = int(input())
print(ans(n))


n = int(input())
repeated = [8, 4, 2, 6]
times = 4
if n == 0:
	print(1)
else:
	print(repeated[(n - 1) % 4])


x = int(input())
l = [8, 4, 2, 6]
print(1 if x == 0 else l[x % 4 - 1])


n = int(input())
a = n % 4
if n == 0:
	print('1')
elif a == 1:
	print('8')
elif a == 2:
	print('4')
elif a == 3:
	print('2')
elif a == 4 or a == 0:
	print('6')


import math
n = int(input())
x = pow(8, n, 10)
print(x)


a = int(input())
print(8 ** ((a - 1) % 4 + 1) % 10 if a else 1)


n = eval(input())
c = n % 4
if n == 0:
	print('1')
elif c == 0:
	print('6')
elif c == 1:
	print('8')
elif c == 2:
	print('4')
elif c == 3:
	print('2')


t = int(input())
if t == 0:
	print('1')
else:
	if t % 4 == 0:
		print('6')
	if t % 4 == 3:
		print('2')
	if t % 4 == 2:
		print('4')
	if t % 4 == 1:
		print('8')


a = int(input())
if a == 0:
	aux = 1
elif a == 1:
	aux = 8
elif a % 8 == 0:
	aux = 6
elif a % 8 == 1:
	aux = 8
elif a % 8 == 2:
	aux = 4
elif a % 8 == 3:
	aux = 2
elif a % 8 == 4:
	aux = 6
elif a % 8 == 5:
	aux = 8
elif a % 8 == 6:
	aux = 4
elif a % 8 == 7:
	aux = 2
print(aux)


import sys
c = int(input())
if c == 0:
	print('1')
	sys.exit()
b = c % 4
if b == 0:
	print('6')
	sys.exit()
if b == 1:
	print('8')
	sys.exit()
if b == 2:
	print('4')
	sys.exit()
if b == 3:
	print('2')
	sys.exit()


from sys import stdin, stdout
n = int(stdin.readline())
units = ['8\n', '4\n', '2\n', '6\n']
if n == 0:
	stdout.write('1\n')
	exit()
stdout.write(units[(n - 1) % 4])


def power(a, n, p):
	res = 1
	while n > 0:
		if n % 2 > 0:
			res = res * a % p
			n -= 1
		else:
			a = a * a % p
			n //= 2
	return res
n = int(input())
print(power(8, n, 10))


arr = [6, 8, 4, 2]
n = int(input())
if n == 0:
	print('1')
	quit()
print(arr[n % 4])


def stepen(degree):
	if degree == 0:
		return 1
	elif degree % 4 == 0:
		return 6
	elif degree % 4 == 1:
		return 8
	elif degree % 4 == 2:
		return 4
	elif degree % 4 == 3:
		return 2
print(stepen(int(input())))


n = int(input())
if n <= 4:
	print(8 ** n % 10)
else:
	print(8 ** ((n - 1) % 4 + 1) % 10)


def p(k):
	(a, i) = (8, 1)
	while k > 0:
		if k % 2 == 1:
			i = i * a % 10
		(a, k) = (a * a % 10, k >> 1)
	return i
print(p(int(input())))


n = int(input())
x = pow(1378, n, 10)
print(x)


n = int(input())
if n % 4 == 0 and n != 0:
	n = 4
elif n > 4 and n % 4 != 0:
	n = n % 4
a = str(8 ** n)
print(a[len(a) - 1])


n = int(input())
print([1, '6842'[n % 4]][n > 0])


from math import pow

def main():
	n = int(input())
	if n == 0:
		print(1)
	elif n == 1:
		print(8)
	elif n == 2:
		print(4)
	else:
		i = n - 3
		i = i % 4
		if i == 0:
			print(2)
		elif i == 1:
			print(6)
		elif i == 2:
			print(8)
		elif i == 3:
			print(4)
main()


n = int(input())
d = {0: 6, 1: 8, 2: 4, 3: 2}
if n == 0:
	print(1)
else:
	g = n % 4
	print(d[g])


n = int(input().strip())
ends = [8, 4, 2, 6]
if n == 0:
	print(1)
else:
	print(ends[n % 4 - 1])


def power(base, exp):
	res = 1
	while exp > 0:
		if exp % 2 == 1:
			res = res * base % 10
		base = base * base % 10
		exp //= 2
	return res
n = int(input())
print(power(8, n))


f = lambda x: [6, 8, 4, 2][x % 4] if x > 0 else 1
print(f(int(input())))


n = int(input())
p = []
for i in range(1, 5):
	t = 8 ** i
	r = str(t)
	p.append(r[-1])
r = n % 4
if n == 0:
	print('1')
else:
	print(p[r - 1])


def p(n):
	if n == 0:
		return 1
	else:
		n = n % 4
		n += 4
	return 8 ** n % 10
n = int(input())
print(p(n))


n = int(input())
print(8 ** ((n % 4 + (n % 4 == 0) * 4) * (n > 0)) % 10)


a = int(input())
sisa = a % 4
periode = [8, 4, 2, 6]
if a == 0:
	print(1)
else:
	print(periode[sisa - 1])


n = int(input())
k = n % 4
if n == 0:
	print(1)
	exit(0)
if k == 0:
	print(6)
elif k == 1:
	print(8)
elif k == 2:
	print(4)
elif k == 3:
	print(2)


message = input()
message = int(message)
pow = message % 4
if message == 0:
	print(str(1))
elif pow == 0:
	print(str(6))
elif pow == 1:
	print(str(8))
elif pow == 2:
	print(str(4))
else:
	print(str(2))


n = int(input())
output = pow(1378, n, 10)
print(output)


x = int(input())
if x == 0:
	print(1)
elif x == 1:
	print(8)
else:
	last = [4, 2, 6, 8]
	print(last[(x - 2) % 4])


import math
n = int(input())
if n == 0:
	print('1')
elif n % 4 == 0:
	print('6')
else:
	mul = 8
	n = n % 4
	print(str(int(math.pow(8, n)))[-1])


import sys
ENDS = (8, 4, 2, 6)
N = int(sys.stdin.readline())
if N:
	result = ENDS[(N - 1) % 4]
else:
	result = 1
print(result)


a = int(input())
b = 1378
print(pow(b, a, 10))


def last_digit_by_multiplication(n):
	last_digit = 8
	for i in range(1, n):
		last_digit = last_digit * 8 % 10
	if n == 0:
		return 1
	else:
		return last_digit

def last_digit_by_hack(n):
	last_digits = [8, 4, 2, 6, 8, 4, 2, 6]
	index = n % len(last_digits) - 1
	if index < 0:
		index = len(last_digits) - 1
	if n == 0:
		return 1
	else:
		return last_digits[index]

def main():
	n = int(input())
	hack = last_digit_by_hack(n)
	print(hack)
main()


import sys
import math

def main():
	n = int(sys.stdin.readline().strip())
	print(1 if n == 0 else '6842'[n % 4])
main()


n = int(input())
if n == 0:
	print(1)
else:
	seq = '6842'
	print(int(seq[n % 4]))


n = int(input())

def power(a, n, mod):
	a = a % 10
	res = 1
	if n == 0:
		return 1
	while n:
		if 1 & n:
			res = res * a % mod
			n -= 1
		else:
			a = a * a % mod
			n //= 2
	return res
print(power(1378, n, 10))


def power(a, pow1, MOD):
	if pow1 == 0:
		return 1
	elif pow1 % 2 == 1:
		return power(a, pow1 - 1, MOD) * a % MOD
	else:
		return power(a, pow1 // 2, MOD) ** 2 % MOD
n = int(input())
MOD = 10
print(power(1378, n, MOD))


n = int(input())
l = [8, 4, 2, 6]
if n == 0:
	print(1)
while n != 0:
	x = (n - 1) % 4
	print(l[x])
	break


def lgpow(a, b, mod):
	r = 1
	i = 0
	while 2 ** i <= b:
		if 2 ** i & b:
			r = r * a % mod
		a = a * a % mod
		i += 1
	return r
n = int(input())
print(lgpow(1378, n, 10))


def printLast(n):
	return pow(8, n, 10)
n = int(input())
print(printLast(n))


def Pow(n):
	a = 1
	ans = 8
	while n:
		if n & 1:
			a = a * ans % 10
		ans = ans * ans % 10
		n = n >> 1
	return a
n = eval(input())
print(Pow(n))


n = int(input())
li = [6, 8, 4, 2]
if n == 0:
	print(1)
	exit(0)
print(li[n % 4])


R = lambda : [*map(int, input().split())]
a = input()
if int(a) > 4:
	a = int(a) % 4
	a = str(a)
	d = {'0': 6, '1': 8, '2': 4, '3': 2, '4': 6}
else:
	d = {'0': 1, '1': 8, '2': 4, '3': 2, '4': 6}
print(d.get(a))


import math, sys
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactors(n):
	factors = []
	i = 2
	while i ** 2 <= n:
		while n % i == 0:
			factors.append(i)
			n //= i
		i += 1
	if n > 1:
		factors.append(n)
	return factors

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def main():
	n = int(input())
	arr = [8, 4, 2, 6]
	if n == 0:
		print(1)
	else:
		print(arr[(n - 1) % 4])
t = 1
for _ in range(t):
	main()


n = int(input())
if n == 0:
	print(1)
else:
	if n % 4 == 0:
		p = 4
	else:
		p = n % 4
	d = pow(8, p)
	print(d % 10)


def q_(x):
	a = 8
	ans = 1
	while x > 0:
		if x & 1:
			ans = ans * a % 10
		a = a * a % 10
		x = x // 2
	print(ans % 10)
c = int(input())
q_(c)


import math

def fact(a, b):
	ans = 1
	for i in range(a, b + 1):
		ans *= i
	return str(ans) - 1

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
n = int(input())
if n == 0:
	print(1)
elif n % 4 == 1:
	print(8)
elif n % 4 == 2:
	print(4)
elif n % 4 == 3:
	print(2)
else:
	print(6)


n = int(input())
answers = {0.25: 8, 0.5: 4, 0.75: 2, 0: 6}

def foo(count):
	if count == 0:
		return 1
	d = count / 4
	return answers.get(d - int(d))
print(foo(n))


def power(x, y):
	res = 1
	while y:
		if y % 2:
			res = res % 10 * (x % 10) % 10
			y = y - 1
		else:
			x = x % 10 * (x % 10) % 10
			y = y // 2
	return res
n = int(input())
a = 8
print(power(a, n) % 10)


def arpa(n):
	return pow(1378, n, 10)
x = input()
print(arpa(int(x)))


n = int(input())
ln = [8, 4, 2, 6]
if n > 4:
	n = n % 4
	print(ln[n - 1])
elif n <= 4 and n > 0:
	print(ln[n - 1])
else:
	print(1)


n = int(input())
ans = 1
x = 1378
while n:
	if n % 2:
		ans = ans * x % 10
	n = n // 2
	x = x * x % 10
print(ans % 10)


import math
n = int(input())
kn = n // 4
a = [8, 4, 2, 6, 1]
key = 0
if n == 0:
	key = 4
elif n % 4 == 0:
	key = 3
elif n < 4:
	key = n - 1
else:
	kn = n
	while math.gcd(4, kn) != 4:
		kn -= 1
	key = n - kn - 1
print(a[key])


n = int(input())
q = n
p = 8 ** 4
p = p % 10
n = n % 4
t = 8 ** n
if q > 4:
	p = p * (t % 10)
	print(p % 10)
else:
	p = 8 ** q
	print(p % 10)


n = int(input())
r = pow(8, n, 10)
print(r)


m = int(input())
print([6, 8, 4, 2][m % 4] if m > 0 else 1)


n = int(input())
if n == 0:
	print(1)
else:
	n = n % 4 + 4
	k = 8 ** n % 10
	print(k)


def arpa(n):
	ls = [6, 8, 4, 2]
	if n == 0:
		return 1
	else:
		k = n % 4
		return ls[k]
n = int(input())
print(arpa(n))


inp = int(input()) - 1
number = [8, 4, 2, 6]
if inp == -1:
	print(1)
elif inp > 100:
	print(number[int(str(inp)[-2:]) % 4])
else:
	print(number[inp % 4])


def main():
	x = int(input())
	if x % 4 == 1:
		print(8)
	elif x % 4 == 2:
		print(4)
	elif x % 4 == 3:
		print(2)
	elif x % 4 == 0 and x != 0:
		print(6)
	else:
		print(1)
main()


def solve(n):
	if n == 0:
		return 1
	p = [8, 4, 2, 6]
	return p[(n - 1) % 4]

def main():
	n = int(input())
	print(solve(n))
main()


l = [8, 4, 2, 6]
s = int(input())
if s == 0:
	print(1)
	exit()
sum = s % 4
print(l[sum - 1])


n = int(input())
if n == 0:
	print(1)
else:
	n = n % 4
	if n == 0:
		print(6)
	else:
		print(8 ** n % 10)


n = int(input())

def exponent(x, n):
	if n <= 0:
		return 1
	if n == 1:
		return x
	if n % 2 == 0:
		return exponent(x * x % 10, n // 2)
	else:
		return x * exponent(x * x % 10, n // 2) % 10
print(exponent(8, n))


try:
	p = int(input())
except:
	exit(1)
if p >= 0 and p <= 10 ** 9:
	r = p % 4
	if r == 1:
		print(8)
	elif r == 2:
		print(4)
	elif r == 3:
		print(2)
	elif p != 0 and r == 0:
		print(6)
	elif p == 0:
		print(1)


from array import *
n = int(input())
print(pow(1378, n, 10))


def result(n):
	L = [6, 8, 4, 2]
	if n == 0:
		return 1
	else:
		return L[n % 4]
n = int(input())
print(result(n))


import math
n = int(input())
l = [6, 8, 4, 2]
if n == 0:
	print(1)
else:
	print(l[n % 4])


import sys
num = int(input())
left = num % 4
if num == 0:
	print(1)
elif left % 4 == 2:
	print(4)
elif left % 4 == 0:
	print(6)
elif left % 4 == 1:
	print(8)
elif left % 4 == 3:
	print(2)


import sys
args = sys.stdin.readline()
n = int(args)
if n == 0:
	number = 1
else:
	m = n % 4
	if m == 0:
		number = 6
	elif m == 2:
		number = 4
	elif m == 3:
		number = 2
	else:
		number = 8
sys.stdout.write(str(number))


n = int(input())
if n == 0:
	print(1)
else:
	while n >= 5:
		temp = n // 5
		n = temp + n % 5
	if n == 0:
		print(8)
	elif n == 1:
		print(8)
	elif n == 2:
		print(4)
	elif n == 3:
		print(2)
	elif n == 4:
		print(6)


import math
N = int(input())
print(pow(1378, N, 100) % 10)


n = int(input())
if n == 0:
	print(1)
else:
	a = 8
	n = n % 4 + 4
	for i in range(1, n):
		a = a * 8 % 10
	print(a)


n = int(input())
if n == 0:
	print(1)
else:
	lst = [8, 4, 2, 6]
	r = n % 4
	print(lst[r - 1])


from sys import stdin
input_n = stdin.readline()
n = int(input_n)
r = [8, 4, 2, 6]
if n == 0:
	print(1)
else:
	print(r[n % 4 - 1])


import math
elNum = int(input())
base = 8
numNew = 8
numNew = pow(base, elNum, 10)
print(int(numNew))


def start_check(a):
	n = a % 4
	if n == 2:
		return 4
	elif n == 3:
		return 2
	elif n == 0:
		return 6
	else:
		return 8
n = int(input())
if n == 0:
	print(1)
else:
	print(start_check(n))


def solve(n, result):
	try:
		return result[n - 1]
	except Exception as e:
		return result[n % len(result) - 1]
n = int(input())
result = [8, 4, 2, 6]
if n == 0:
	print(1)
else:
	print(solve(n, result))


n = int(input())
if n == 1:
	print(8)
elif n == 0:
	print(1)
else:
	n = n % 4 if n % 4 != 0 else 4
	print(str(8 ** n)[-1])


inn = int(input())
if inn == 0:
	print(1)
elif inn % 4 == 0:
	print(6)
elif inn % 4 == 1:
	print(8)
elif inn % 4 == 2:
	print(4)
else:
	print(2)


n = int(input())
if n > 4:
	n = 4 + n % 4
print(8 ** n % 10)


n = int(input())
if n == 0:
	print('1')
	exit()
dict1 = {0: 6, 1: 8, 2: 4, 3: 2}
print(dict1[n % 4])


n = int(input())
res = 2 ** n % 10
if n % 2 == 0:
	print(res)
else:
	print(10 - res)


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
print(pow(1378, read_int(), 10))


num = int(input())
if num == 0:
	print(1)
else:
	aa = [6, 8, 4, 2]
	print(aa[num % 4])


import sys
import io
import os

def solve():
	last_digit = {0: 6, 1: 8, 2: 4, 3: 2}
	n = int(input().decode())
	if n == 0:
		return 1
	else:
		return last_digit[n % 4]

def main():
	ans = solve()
	sys.stdout.write(str(ans))
	sys.stdin.close()
	sys.stdout.close()
if __debug__:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
main()


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = 1
mod = 1000000.0 + 3
for _ in range(t):
	lol = [8, 4, 2, 6]
	n = ii()
	if n == 0:
		print(1)
	elif n < 5:
		print(lol[n - 1])
	else:
		print(lol[n % 4 - 1])


def power(b, p, m):
	res = 1
	while p > 0:
		if p % 2 == 0:
			b = b * b % m
			p = p / 2
		else:
			res = res * b % m
			p = p - 1
	return res
n = int(input())
ans = power(8, n, 10)
print(ans)


import math
n = int(input())
if n == 0:
	print(1)
else:
	n = n % 4 + 4
	print(pow(1378, n, 10))


def power(x):
	if x == 0:
		return 1
	elif x % 4 == 3:
		return 2
	elif x % 4 == 1:
		return 8
	elif x % 4 == 2:
		return 4
	else:
		return 6
print(power(int(input())))


def exp(a, b, m):
	if b == 0:
		return 1
	elif b % 2 == 0:
		return exp(a * a % m, b // 2, m)
	else:
		return a * exp(a * a % m, (b - 1) / 2, m) % m
n = int(input())
res = exp(1378, n, 10)
print(res)


n = int(input())
last = [8, 4, 2, 6]
if n == 0:
	print('1')
else:
	print(str(last[n % 4 - 1]))


num = int(input())
m = 1378
print(pow(m, num, 10))


import math, sys, re, itertools, pprint, collections, copy
(rs, ri, rai, raf) = (input, lambda : int(input()), lambda : list(map(int, input().split())), lambda : list(map(float, input().split())))
n = ri()
if n == 0:
	print(1)
else:
	print([8, 4, 2, 6][(n - 1) % 4])


N = int(input())
base = 1378
mod = 10
result = 1
while N > 0:
	if N % 2 == 1:
		result = result * base % mod
	N //= 2
	base = base * base % mod
print(result)


from sys import stdin, stdout
n = int(stdin.readline())
a = [8]
if n == 0:
	stdout.write('1')
else:
	for i in range(n + 1):
		x = a[i] * 8 % 10
		if x == 8:
			break
		a.append(x)
	stdout.write(str(a[(n - 1) % len(a)]))


n = int(input())
x = pow(8, n, 10)
print(x)


def read_ints():
	temp = input()
	ints = [int(t) for t in temp.split(' ')]
	return ints
N = int(input())
mod = N % 4
result = [6, 8, 4, 2][mod]
if N == 0:
	result = 1
print(result)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
import threading
import bisect
import operator
import heapq
from atexit import register
from io import BytesIO
import io
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
if n == 0:
	print(1)
	sys.exit(0)
n = n % 4
if n == 1:
	print(8)
elif n == 2:
	print(4)
elif n == 3:
	print(2)
else:
	print(6)


f = lambda : map(int, input().split())
l = [6, 8, 4, 2]
n = int(input())
print([l[n % 4], 1][n == 0])


import sys

def main():
	print(power(1378, int(sys.stdin.readline()), mod=10))

def power(a, n, mod):
	cur_power = a
	ans = 1
	for i in range(32):
		if n & 1 << i:
			ans *= cur_power
		cur_power *= cur_power
		cur_power %= mod
	ans %= mod
	return ans
main()


def f(n):
	l = [6, 8, 4, 2]
	if n == 0:
		return 1
	return l[n % 4]
n = int(input())
print(f(n))


import sys
I = sys.stdin.readline
n = int(input())
if n == 0:
	print(1)
else:
	d = {1: 8, 2: 4, 3: 2, 0: 6}
	print(d[n % 4])


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
import math
n = ip()
if n == 0:
	print(1)
	exit()
x = n % 4
if x == 0:
	x = 4
print(str(8 ** x)[-1])


from time import time
import math
import os
import sys
from math import *
from io import BytesIO, IOBase
from collections import *
from bisect import *
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def prog_name():
	n = int(input())
	if n == 0:
		print(1)
	elif n % 4 == 0:
		print(6)
	elif n % 4 == 1:
		print(8)
	elif n % 4 == 2:
		print(4)
	else:
		print(2)

def main():
	T = 1
	for unique in range(T):
		prog_name()
main()


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
if n == 0:
	print(1)
elif n % 4 == 0:
	print(6)
else:
	n = n % 4
	res = 8 ** n
	print(res % 10)


n = int(input())
if n == 0:
	print(1)
else:
	table = []
	for i in range(1, 5):
		table.append(int(str(1278 ** i)[-1]))
	print(table[n % 4 - 1])


n = int(input())

def solve():
	last_number = [6, 8, 4, 2]
	if n == 0:
		return 1
	else:
		pos = n % 4
		return last_number[pos]
result = solve()
print(result)


import math
n = int(input())
kn = n // 4
a = [8, 4, 2, 6, 1]
key = 0
if n == 0:
	key = 4
elif n % 4 == 0:
	key = 3
elif n == 1:
	key = 0
elif n == 2:
	key = 1
elif n == 3:
	key = 2
else:
	kn = n
	while math.gcd(4, kn) != 4:
		kn -= 1
	for i in range(kn - 1, n + 1):
		key += 1
		if key == 3:
			key = 0
		h = key
print(a[key])


n = int(input())
if n == 0:
	print(1)
else:
	l = n % 4
	if l == 0:
		l = 4
	r = 8 ** l % 10
	print(r)


t = int(input())
a = t % 4
if t == 0:
	print(1)
elif a % 2 == 0 and a % 4 != 0:
	print(4)
elif a == 0:
	print(6)
elif a % 3 == 0:
	print(2)
else:
	print(8)


import sys
input = sys.stdin.readline
n = int(input().strip())
if n == 0:
	print(1)
elif n % 4 == 1:
	print(8)
elif n % 4 == 2:
	print(4)
elif n % 4 == 3:
	print(2)
else:
	print(6)


def prn(n):
	print(n)
n = int(input())
if n == 0:
	print(1)
else:
	m = n % 4
	if m == 1:
		prn(8)
	elif m == 2:
		prn(4)
	elif m == 3:
		prn(2)
	else:
		prn(6)


import sys
input = sys.stdin.readline

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().split()))
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = [8, 4, 2, 6]
if n == 0:
	print(1)
else:
	n = (n - 1) % 4
	print(a[n])


n = int(input())
l = [8, 4, 2, 6]
if n % 4 == 0 and n != 0:
	ind = 3
	print(l[ind])
elif n != 0 and n < 4:
	ind = n - 1
	print(l[ind])
elif n == 0:
	print(1)
else:
	ind = n % 4 - 1
	print(l[ind])


n = int(input())
print('6842'[n % 4] if n else 1)


def main():
	exp = int(input())
	data = [8, 4, 2, 6]
	print(data[(exp - 1) % 4] if exp else 1)
main()


from math import ceil, sqrt, floor
import sys
n = int(input())
if n == 0:
	print(1)
else:
	print([8, 4, 2, 6][(n - 1) % 4])


number = int(input())
answer = pow(1378, number, 10)
print(answer)


x = int(input())
z = 1
if x == 0:
	print(1)
	exit()
l = [8, 4, 2, 6]
print(l[(x - 1) % 4])


n = int(input())
if n % 4 == 0 and n != 0:
	t = 4
else:
	t = n % 4
t = pow(8, t)
t %= 10
print(t)


def solution(a):
	if a % 4 == 0:
		print(6)
	elif a % 4 == 1:
		print(8)
	elif a % 4 == 2:
		print(4)
	else:
		print(2)
n = input()
if len(n) == 1:
	n = int(n[-1])
	if n == 0:
		print(1)
	else:
		solution(n)
else:
	n = int(n[-1]) + 10 * int(n[-2])
	solution(n)


stre = '6842'
Input = int(input())
print([stre[Input % 4], 1][Input == 0])


n = int(input())
pow8 = {1: 8, 2: 4, 3: 2, 4: 6}
p = n % 4
if n == 0:
	print(1)
else:
	if p == 0:
		p = 4
	print(pow8[p])


n = int(input())
m = n % 4
w = 1378 ** m
if n == 0:
	print('1')
elif n % 4 != 0:
	print(w % 10)
else:
	print('6')


n = int(input())
remainder = 1
if n != 0:
	n = n % 4 + 4
for x in range(n):
	remainder = remainder * 8 % 10
print(remainder)


def oss(n):
	if n != 0 and n % 4 == 0:
		return 6
	else:
		return 1378 ** (n % 4) % 10
print(oss(int(input())))


n = int(input())
if n == 0:
	print(1)
else:
	n %= 4
	res = 6
	for i in range(1, n + 1):
		res *= 8
	print(res % 10)


n = int(input())
if n == 0:
	print(1)
	exit(0)
n %= 4
if n == 0:
	print(6)
	exit(0)
print(8 ** n % 10)


n = int(input())
ans = 8
if n == 1:
	print(ans)
elif n == 0:
	print(1)
else:
	x = [8, 4, 2, 6]
	y = n % 4
	ans = x[y - 1]
	print(ans)


from os import sys
c = [8, 4, 2, 6]
n = int(sys.stdin.readline())
if n == 0:
	print(1)
else:
	print(c[n % 4 - 1])


def lol(a, b):
	if b == 1:
		return a % 10
	elif b % 2 == 1:
		return a % 10 * lol(a % 10, b // 2) ** 2 % 10
	else:
		return lol(a % 10, b // 2) ** 2 % 10
n = int(input(''))
if n == 0:
	print(1)
else:
	print(lol(8, n))


n = 1378
b = int(input())
c = 8
d = b % 4
if b == 0:
	print(1)
elif d == 0:
	print(6)
else:
	print(c ** d % 10)


n = int(input())
if n == 0:
	print(1)
else:
	n = n - 1
	tab = [8, 4, 2, 6]
	index = n % 4
	print(tab[index])


n = int(input())
lst = [8, 4, 2, 6]
if n == 0:
	print('1')
elif n > 0:
	i = (n - 1) % 4
	print(lst[i])


s = input().strip()
if s != '0':
	if len(s) == 1:
		s = '0' + s
	n = int(s[-2:]) % 4
	if n == 1:
		print(8)
	elif n == 2:
		print(4)
	elif n == 3:
		print(2)
	else:
		print(6)
else:
	print(1)


def pow(x, k):
	if k == 0:
		return 1
	a = pow(x, int(k / 2))
	a = a * a
	if k % 2 == 1:
		a = a * x
	a = a % 10
	return int(a)
a = int(input().strip())
print(pow(1378, a))


import sys
import math
input = sys.stdin.readline

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
n = int(input())
a = [8, 4, 2, 6]
if n == 0:
	print(1)
else:
	print(a[(n - 1) % 4])


order = int(input())
t = 8
if order == 0:
	print(1)
elif order % 4 == 1:
	print(8)
elif order % 4 == 2:
	print(4)
elif order % 4 == 3:
	print(2)
elif order % 4 == 0:
	print(6)


n = int(input())
if n == 0:
	print(1)
elif n in range(1, 10 ** 9 + 1, 4):
	print(8)
elif n in range(2, 10 ** 9 + 1, 4):
	print(4)
elif n in range(3, 10 ** 9 + 1, 4):
	print(2)
else:
	print(6)


x = int(input())
r = pow(1378, x, 10)
print(r)


n = int(input())
exp = 0
if n != 0:
	if n % 4 == 0:
		exp = 4
	elif n % 4 != 0:
		exp = n % 4
elif n == 0:
	exp = 0
print(pow(8, exp) % 10)


def ans(t):
	if t == 0:
		return 1
	tmp = [6, 8, 4, 2]
	t = t % 4
	return tmp[t]
t = int(input())
print(ans(t))


n = int(input())
if n == 0:
	print(1)
elif n < 5:
	print(str(1378 ** n)[-1:])
elif n % 4 == 0:
	print(6)
else:
	print(str(1378 ** (n % 4))[-1:])


n = int(input())
ans = {1: 8, 2: 4, 3: 2, 4: 6}
if n < 5 and n > 0:
	print(ans[n])
elif n == 0:
	print(1)
elif n % 4 == 0:
	print(ans[4])
else:
	print(ans[n % 4])


import sys
n = int(input())
if n == 0:
	print(1)
	exit()
arr = [6, 8, 4, 2]
print(arr[n % 4])


from sys import stdin, stdout
n = int(stdin.readline())
if not n:
	stdout.write('1')
else:
	n %= 4
	if not n:
		stdout.write('6')
	else:
		stdout.write(str(8 ** n)[-1])


import sys
import math
import bisect
import itertools
import random
import re

def main():
	n = int(input())
	if n == 0:
		print(1)
	else:
		n = n % 4 + 4
		r = 8 ** n % 10
		print(r)
main()


def main():
	n = int(input())
	print((6, 8, 4, 2)[n % 4] if n else 1)
main()


import sys
n = int(sys.stdin.readline())
if n == 0:
	print(1)
else:
	n = (n - 1) % 4
	d = [8, 4, 2, 6]
	print(d[n])


def cal(n):
	if n == 0:
		return 1
	if n == 1:
		return 8
	k = cal(int(n / 2))
	if n % 2 == 0:
		return k * k % 10
	else:
		return k * k * 8 % 10
n = int(input())
print(cal(n))


import sys

def BigMod(a, p, m):
	if p == 0:
		return 1
	if p % 2:
		return a % m * BigMod(a, p - 1, m)
	else:
		c = BigMod(a, p / 2, m)
		return c % m * (c % m) % m
B = 1378
P = int(input())
M = 10
if P == 0:
	print(1)
else:
	print(BigMod(B, P, M) % 10)


n = int(input())
d = [4, 2, 6, 8]
if n == 1:
	print(8)
elif n == 0:
	print(1)
else:
	x = (n - 2) % 4
	print(d[x])


from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def inn():
	return int(input())
mo = 1000000007
n = inn()
d = {1: 8, 2: 4, 3: 2, 0: 6}
if n == 0:
	print(1)
	exit()
print(d[n % 4])


try:
	n = int(input())
	if n == 0:
		print(1)
	elif n % 4 == 1:
		print(8)
	elif n % 4 == 2:
		print(4)
	elif n % 4 == 3:
		print(2)
	else:
		print(6)
except:
	pass


def solve(n):
	if not n:
		return 1
	arr = [8, 4, 2, 6, 8, 4, 2, 6, 8, 4, 2, 6, 8, 4, 2, 6, 8, 4, 2, 6]
	return arr[n % 20 - 1]

def main():
	n = int(input())
	print(solve(n))
main()


from sys import stdin, stdout
import sys
import math

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
n = get_int()
if n == 0:
	print(1)
else:
	ar = [6, 8, 4, 2]
	print(ar[n % 4])


n = int(input())
last_digit = {0: 6, 1: 8, 2: 4, 3: 2}
if n == 0:
	print(1)
else:
	x = n % 4
	print(last_digit[x])


import sys
n = sys.stdin.readline()
a = [8, 4, 2, 6]
k = int(n)
if k == 0:
	print(1)
else:
	k = k % 4
	print(a[k - 1])


n = int(input())
while n > 400:
	n -= 400
while n > 40:
	n -= 40
while n > 4:
	n -= 4
print([1, 8, 4, 2, 6][n])


n = int(input())
if n % 1000 == 0 and n != 0:
	n = 100
print(8 ** (n % 1000) % 10)


def main():
	try:
		while True:
			n = int(input())
			x = 1
			a = 1378
			while n != 0:
				if n & 1:
					x *= a
					x %= 10000
				a *= a
				a %= 10000
				n >>= 1
			print(x % 10)
	except EOFError:
		pass
main()


n = int(input())

def pow(n, k):
	if k <= 1:
		return {0: 1, 1: n}[k]
	tmp = pow(n, k // 2)
	ret = tmp * tmp * (1 if k & 1 == 0 else n)
	return ret % 10
print(pow(8, n))


x = int(input())
s = pow(1378, x, 10)
print(s)


n = int(input())
output = 0
q = 0
k = (n - 1) % 4
if k == 0:
	output = 8
elif k == 1:
	output = 4
elif k == 2:
	output = 2
elif k == 3:
	output = 6
if n == 1:
	output = 8
if n == 0:
	output = 1
print(output)


def f(n):
	if n == 0:
		return 1
	else:
		n = (n - 1) % 4
		if n == 0:
			return 8
		elif n == 1:
			return 4
		elif n == 2:
			return 2
		else:
			return 6
n = int(input())
print(f(n))


n = int(input())

def exp(a):
	if a == 0:
		return 1
	if a == 1:
		return 8
	v = exp(a // 2)
	if a % 2 == 0:
		return v * v % 10
	else:
		return v * v * 8 % 10
print(exp(n))


n = int(input())
if n == 0:
	print(1)
else:
	print(list('6842')[n % 4])


k = int(input().strip())
n = k % 4
if k == 0:
	print(1)
elif n == 0:
	print(6)
elif n == 1:
	print(8)
elif n == 2:
	print(4)
else:
	print(2)


exp = int(input())
if exp == 0:
	lstDigit = 1
else:
	modExp = exp % 4
	if modExp == 1:
		lstDigit = 8
	elif modExp == 2:
		lstDigit = 4
	elif modExp == 3:
		lstDigit = 2
	else:
		lstDigit = 6
print(lstDigit)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
m = get_int()
d = {1: 8, 2: 4, 3: 2, 0: 6}
if m != 0:
	m = m % 4
	print(d[m])
else:
	print(1)


n = int(input())
if n == 0:
	print('1')
elif n % 4 == 0:
	print('6')
else:
	for i in range(n):
		if 1 + i * 4 == n:
			print('8')
			break
		elif 2 + i * 4 == n:
			print('4')
			break
		elif 3 + i * 4 == n:
			print('2')
			break


s = {1: 8, 2: 4, 3: 2, 0: 6}
a = int(input())
if a == 0:
	print(1)
else:
	print(s[a % 4])


import math
import os
import random
import re
import sys
n = int(input())
k = n - n // 4 * 4
if n == 0:
	print(1)
elif k == 1:
	print(8)
elif k == 2:
	print(4)
elif k == 3:
	print(2)
elif k == 0:
	print(6)


import math
n = int(input())
if n == 0:
	print('1')
elif n % 4 != 0:
	print(int(math.pow(8, n % 4) % 10))
else:
	print('6')


n = int(input())
last = [8, 4, 2, 6]
if n == 0:
	print(1)
	exit()
rem = n % 4
if n % 4 == 0:
	print(last[3])
	exit()
print(last[rem - 1])
exit()


n = int(input())
res = int(pow(1378, n, 10))
print(res)


is_debug = False
n = int(input())
a = [8, 4, 2, 6]
if n == 0:
	print(f'1')
else:
	n = (n - 1) % 4
	print(f'n={n}') if is_debug else ''
	print(f'{a[n]}')


import math
n = int(input())
if n == 0:
	print(1)
if n != 0:
	for i in range(1, 5):
		if (n + 4 - i) % 4 == 0:
			if i == 1:
				print(8)
			if i == 2:
				print(4)
			if i == 3:
				print(2)
			if i == 4:
				print(6)
			break


hat = int(input())
lst = [8, 4, 2, 6]
if hat == 0:
	print(1)
else:
	print(lst[hat % 4 - 1])


def power(val, n, mod):
	res = 1
	while n:
		if n % 2 == 0:
			val = val * val % mod
			n = n // 2
		else:
			res = res * val % mod
			n = n - 1
	return res
n = int(input())
print(power(8, n, 10))


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = int(inp())
d = [8, 4, 2, 6]
if n == 0:
	print(1)
else:
	print(d[(n - 1) % 4])


n = int(input())
h = {'1': 8, '2': 4, '3': 2, '0': 6}
if n > 0:
	a = n % 4
	print(h[str(a)])
else:
	print(1)


import math

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime
get_int = lambda : map(int, input().split())
a = int(input())
ans = [8, 4, 2, 6]
if a == 0:
	print(1)
else:
	print(ans[(a - 1) % 4])


N = int(input())
if N == 0:
	print(1)
else:
	N %= 4
	if N == 0:
		print(6)
	else:
		print(8 ** N % 10)