---
{"category_name":"easy","problem_code":"RECHEND","problem_name":"Can You Reach The End","problemComponents":{"constraints":"- $1 \\le T \\le 1000$\n- $2 \\le N \\le 10^6$\n- $1 \\le X_i,Y_i \\le N$\n- $(X_i, Y_i) \\ne (1, 1)$ and $(X_i, Y_i) \\ne (N, N)$ for all $1 \\le i \\le N$\n- $X_i \\ne X_j$ and $Y_i \\ne Y_j$ for all $1 \\le i \\lt j \\le N$\n- Sum of $N$ over all test cases does not exceed $10^6$","constraintsState":true,"subtasks":"- 30 points : $1 \\leq R \\leq 10000$\n- 70 points : $1 \\leq R \\leq 10^9$\n","subtasksState":false,"inputFormat":"- The first line contains $T$ - the number of test cases. Then the test cases follow.\n- The first line of each test case contains $N$ - the size of the square grid.\n- The $i$-th line of the next $N$ lines contains two integers $X_i$ and $Y_i$ indicating that $(X_i, Y_i)$ is the position of a block in the grid.\n\n","inputFormatState":true,"outputFormat":"For each test case, if there exists a path from $(1,1)$ to $(N,N)$, output `YES`, otherwise output `NO`.\n\nYou may print each character of the string in uppercase or lowercase (for example, the strings `yEs`, `yes`, `Yes` and `YES` will all be treated as identical).","outputFormatState":true,"sampleTestCases":{"0":{"id":1,"input":"2\n3\n1 2\n2 3\n3 1\n2\n1 2\n2 1","output":"YES\nNO","explanation":"- **Test case $1$:** We can follow the path $(1,1) \\to (2,1) \\to (2,2) \\to (3,2) \\to (3,3)$.\n\n\u003Cimg src=\u0022https://i.ibb.co/kgJhzGb/explanation.pngg\u0022 width=\u0022450\u0022 height=\u0022378\u0022 /\u003E\n\n- **Test case $2$:** We can\u0027t move from the starting point, so it is impossible to reach $(N, N)$.","isDeleted":false}}},"video_editorial_url":"https://youtu.be/efV982GTC9o","languages_supported":{"0":"CPP14","1":"C","2":"JAVA","3":"PYTH 3.6","4":"CPP17","5":"PYTH","6":"PYP3","7":"CS2","8":"ADA","9":"PYPY","10":"TEXT","11":"PAS fpc","12":"NODEJS","13":"RUBY","14":"PHP","15":"GO","16":"HASK","17":"TCL","18":"PERL","19":"SCALA","20":"LUA","21":"kotlin","22":"BASH","23":"JS","24":"LISP sbcl","25":"rust","26":"PAS gpc","27":"BF","28":"CLOJ","29":"R","30":"D","31":"CAML","32":"FORT","33":"ASM","34":"swift","35":"FS","36":"WSPC","37":"LISP clisp","38":"SQL","39":"SCM guile","40":"PERL6","41":"ERL","42":"CLPS","43":"ICK","44":"NICE","45":"PRLG","46":"ICON","47":"COB","48":"SCM chicken","49":"PIKE","50":"SCM qobi","51":"ST","52":"SQLQ","53":"NEM"},"max_timelimit":1,"source_sizelimit":50000,"problem_author":"dazlersan1","problem_tester":"","date_added":"20-10-2021","tags":{"0":"cook134","1":"dazlersan1","2":"easy"},"problem_difficulty_level":"Unavailable","best_tag":"","editorial_url":"https://discuss.codechef.com/problems/RECHEND","time":{"view_start_date":1635100202,"submit_start_date":1635100202,"visible_start_date":1635100202,"end_date":1735669800},"is_direct_submittable":false,"problemDiscussURL":"https://discuss.codechef.com/search?q=RECHEND","is_proctored":false,"visitedContests":{},"layout":"problem"}
---
### Read problem statements in [Mandarin](https://www.codechef.com/download/translated/COOK134/mandarin/RECHEND.pdf), [Bengali](https://www.codechef.com/download/translated/COOK134/bengali/RECHEND.pdf), and [Russian](https://www.codechef.com/download/translated/COOK134/russian/RECHEND.pdf) as well.
You are given a positive integer $N$. Consider a square grid of size $N \times N$, with rows numbered $1$ to $N$ from top to bottom and columns numbered $1$ to $N$ from left to right. Initially you are at $(1,1)$ and you have to reach $(N,N)$. From a cell you can either move one cell to the right or one cell down (if possible). Formally, if you are at $(i,j)$, then you can either move to $(i+1,j)$ if $i \lt N$, or to $(i,j+1)$ if $j \lt N$.
There are exactly $N$ blocks in the grid, such that each row contains exactly one block and each column contains exactly one block. You can't move to a cell which contains a block. It is guaranteed that blocks will not placed in $(1,1)$ and $(N,N)$.
You have to find out whether you can reach $(N,N)$.
<aside style='background: #f8f8f8;padding: 10px 15px;'><div>All submissions for this problem are available.</div></aside>