using System; using System.Collections.Generic; using System.Linq; // https://yukicoder.me/problems/no/2921 class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("5"); WillReturn.Add("6 7"); WillReturn.Add("5 14"); WillReturn.Add("18 6"); WillReturn.Add("1 18"); WillReturn.Add("9 17"); } else if (InputPattern == "Input2") { WillReturn.Add("6"); WillReturn.Add("7764 52463"); WillReturn.Add("1658 7836"); WillReturn.Add("657456 647734"); WillReturn.Add("64567 734634"); WillReturn.Add("476 857467"); WillReturn.Add("48756587 675761"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); long[] wkArr = { }; Action SplitAct = pStr => wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray(); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); Solve(wkArr[0], wkArr[1]); } } static void Solve(long pN, long pM) { long NeedTukue = pN / 4; if (pN % 4 > 0) { NeedTukue++; } long RestSeat = NeedTukue * 8 - pN; pM -= RestSeat; if (pM > 0) { NeedTukue += pM / 8; if (pM % 8 > 0) { NeedTukue++; } } Console.WriteLine(NeedTukue); } }