F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Acesrc and Hunting

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 753    Accepted Submission(s): 227
Special Judge


Problem Description
Acesrc is a famous hunter at Nanjing University second to none. Recently, he set $n \times m$ traps in Yangshan Park, a park near Nanjing University Xianlin Campus, arranged in $n$ rows and $m$ columns. The rows are numbered $1$ through $n$ from bottom to up, and the columns are numbered $1$ through $m$ from left to right. The distance between two adjacent traps, both horizontally and vertically, is 1 meter.

Today, Acesrc happily finds that every trap he set has captured an animal. He decides to collect these hunted animals to make roast meat for his friends. However, collecting these animals normally is too boring, so he decides to find a route following the rules below:

1. Acesrc can choose any trap to start; every time he collects the animal in the trap, he moves to some unvisited trap and repeats until all captured animals are collected;
2. The Euclidean distance he moves from one trap to the next trap should be between 1 meter and 3 meters exclusive; that is, the distance should be strictly greater than 1 meter and strictly less than 3 meters.

Acesrc has quickly collected all animals. Roo wonders how Acesrc collected these animals, but Acesrc buttons up his lip. Can you give a possible route to collect all the animals?
 

Input
The first line of input consists of a single integer $T$ $(1 \leq T \leq 240)$, the number of test cases. Each test case is a single line of two integers $n, m$ $(1 \leq n, m \leq 100)$, denoting the size of the trap matrix.
 

Output
For each test case, if it is impossible to find any valid route, print NO in a single line; otherwise, print YES in one line, followed by $n \times m$ lines describing the route, each of these lines containing two integers $x, y$ $(1 \leq x \leq n, 1 \leq y \leq m)$, denoting the position of a trap visited. If multiple solutions exist, print any.
 

Sample Input
2 2 2 2 3
 

Sample Output
NO YES 1 1 2 2 1 3 2 1 1 2 2 3
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-29 14:24:58, Gzip enabled