We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Mathematics
  3. Number Theory
  4. Computer Virus

Computer Virus

Problem
Submissions
Leaderboard
Discussions
Editorial

Suppose we have an n-dimensional supercomputer with an infinite number of processors. Every processor has a vector of integers as its (n-dimensional) coordinates and can be thought of as a point in the -dimensional space. Furthermore, at every -dimensional lattice point, there is a processor. Two processors are called neighbors if their coordinate vectors are different in only one position, and the absolute difference of the numbers in that position is equal to . For example and are neighbors, and so are and . But and , and and , are not neighbors.

Some processors of this computer are infected by a virus. At time , only one processor is infected. After every second, all uninfected processors that are neighbors with infected ones become infected too. Given and , calculate the number of processors that are infected after seconds, modulo .

Input Format

The first line contains an integer , the number of test cases.
Each of the next lines contains two integers and , separated by a space.

Output Format

For every test case, write the answer in a single line.

Constraints




The sum of all 's in one file does not exceed

Sample Input

5
2 0
2 1
2 2
3 1
1 10

Sample Output

1
5
13
7
21

Explanation

Author

demidenko

Difficulty

Advanced

Max Score

100

Submitted By

186

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy