using System;
using System.Numerics;
public class Program
{
public static void Main()
BigInteger j=0, m = BigInteger.Parse(Console.ReadLine());
a1: j++; BigInteger n = BigInteger.Parse(Console.ReadLine());
BigInteger s = 0, k = 1, i = 1, t, b = 0;
for (i = 0;i<n ; i++)
t = b;
b = s;
s = k + t;
k = s;
}
Console.WriteLine(s%10);
if (j<m) goto a1;