/// <summary>
    /// Explanation :
    /// </summary>
    /// <param name="args"></param>
    public static void Main(string[] args)
    {
        try
        {
            int C = int.Parse(Console.ReadLine());
            for (int i = 1; i <= C; i++)
            {
                try
                {
                    int D = int.Parse(Console.ReadLine());
                    LinkedList <Door> doors = new LinkedList <Door>();
                    for (int j = 0; j < D; j++)
                    {
                        string[] stringParts = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        int      P           = int.Parse(stringParts[0]);
                        int      T           = int.Parse(stringParts[1]);
                        doors.AddLast(new Door {
                            Period = P, TimePassed = T
                        });
                    }
                    Doorscurity doorscurity = new Doorscurity(doors.ToArray());
                    var         doorsCopy   = doors.Select(d => new Door {
                        Independent = d.Independent, Index = d.Index, Period = d.Period, TimePassed = d.TimePassed
                    }).ToArray();
                    string prefixString = "Case #" + i + ": ";

                    if (doorscurity.Solve(out Number result))
                    {
                        Console.WriteLine(prefixString + result);
                        if (!Doorscurity.VerifyFeasible(doorsCopy, result))
                        {
                            Console.WriteLine("BAAAAD ANSWER");
                            Console.WriteLine(D);
                        }
                    }
                    else
                    {
                        Console.WriteLine(prefixString + "NEVER");
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Case #" + i + ": ");
                    Console.WriteLine(exception);
                }
            }
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
        }
    }
        public void TestMethod10()
        {
            Door[] doors = new Door[]
            {
                new Door {
                    Period = 2, TimePassed = 0
                }
            };
            Doorscurity doorscurity = new Doorscurity(doors);

            Assert.IsTrue(doorscurity.Solve(out Number result));
            Assert.IsTrue(result == 0);
        }
        public void TestMethod12()
        {
            Door[] doors = new Door[]
            {
                new Door {
                    Period = 5, TimePassed = 2
                }
                , new Door {
                    Period = 9, TimePassed = 3
                }
                , new Door {
                    Period = 7, TimePassed = 2
                }
            };
            Doorscurity doorscurity = new Doorscurity(doors);

            Assert.IsTrue(doorscurity.Solve(out Number result));
            Assert.IsTrue(result == 248);
        }
    /// <summary>
    /// Explanation :
    /// </summary>
    /// <param name="args"></param>
    public static void Main(string[] args)
    {
        try
        {
            int C = int.Parse(Console.ReadLine());
            for (int i = 1; i <= C; i++)
            {
                try
                {
                    int D = int.Parse(Console.ReadLine());
                    LinkedList <Door> doors = new LinkedList <Door>();
                    for (int j = 0; j < D; j++)
                    {
                        int P = int.Parse(Console.ReadLine());
                        int T = int.Parse(Console.ReadLine());
                        doors.AddLast(new Door {
                            Period = P, TimePassed = T
                        });
                    }
                    Doorscurity doorscurity  = new Doorscurity(doors.ToArray());
                    string      prefixString = "Case #" + i + ": ";

                    if (doorscurity.Solve(out int result))
                    {
                        Console.WriteLine(prefixString + result);
                    }
                    else
                    {
                        Console.WriteLine(prefixString + "NEVER");
                    }
                }
                catch (Exception exception)
                {
                    Console.WriteLine("Case #" + i + ": ");
                    Console.WriteLine(exception);
                }
            }
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception);
        }
    }
        public void TestMethod13()
        {
            Door[] doors = new Door[]
            {
                new Door {
                    Period = 7, TimePassed = 2
                }
                , new Door {
                    Period = 23, TimePassed = 20
                }
                , new Door {
                    Period = 21, TimePassed = 20
                }
                , new Door {
                    Period = 27, TimePassed = 3
                }
            };
            Doorscurity doorscurity = new Doorscurity(doors);

            Assert.IsFalse(doorscurity.Solve(out Number result));
        }
        public void TestMethod9()
        {
            Door[] doors = new Door[]
            {
                new Door {
                    Period = 2, TimePassed = 1
                }
                , new Door {
                    Period = 3, TimePassed = 1
                }
                , new Door {
                    Period = 4, TimePassed = 1
                }
                , new Door {
                    Period = 4, TimePassed = 1
                }
            };
            Doorscurity doorscurity = new Doorscurity(doors);

            Assert.IsFalse(doorscurity.Solve(out Number result));
        }
        public void TestMethod14()
        {
            Door[] doors = new Door[]
            {
                new Door {
                    Period = 59, TimePassed = 23
                }
                , new Door {
                    Period = 65, TimePassed = 25
                }
                , new Door {
                    Period = 34, TimePassed = 15
                }
                , new Door {
                    Period = 9, TimePassed = 3
                }
            };
            Doorscurity doorscurity = new Doorscurity(doors);

            Assert.IsTrue(doorscurity.Solve(out Number result));
            Assert.IsTrue(result == 711399);
        }