// Arup Guha
// 9/30/2015
// Solution to 2003 UCF HS Contest Problem: Darts

import java.util.*;

public class darts {

	// Points for each segment of the board, with board broken up into 40 slices, starting at angle 0.
	final public static int[] POINTS = {6,13,13,4,4,18,18,1,1,20,20,5,5,12,12,9,9,14,14,11,11,8,8,16,16,7,7,19,19,3,3,17,17,2,2,15,15,10,10,6};

	// Lots of constants...
	final public static int INNER_RADIUS = 7;
	final public static int INNER_POINTS = 50;
	final public static int OUTER_RADIUS = 16;
	final public static int OUTER_POINTS = 25;
	final public static int TRIPLE_RING = 107;
	final public static int DOUBLE_RING = 170;
	final public static int BONUS_WIDTH = 8;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process all cases.
		for (int loop=0; loop<numCases; loop++) {
			double x = stdin.nextDouble();
			double y = stdin.nextDouble();
			System.out.println(score(x,y));
		}
	}

	public static int score(double x, double y) {

		// Change to polar coordinates...
		double mag = Math.sqrt(x*x+y*y);
		double angle = Math.atan2(y, x);
		if (angle < 0) angle += 2*Math.PI;

		// Bulls and bad shots are easy.
		if (mag < INNER_RADIUS) return INNER_POINTS;
		if (mag < OUTER_RADIUS) return OUTER_POINTS;
		if (mag > DOUBLE_RING) return 0;

		// Note: No epsilon is added since no pts will be exactly on any border.
		int index = (int)((angle*180/Math.PI)/9);

		// Now, just check whether we multiply by 1, 2 or 3...
		if (mag > TRIPLE_RING-BONUS_WIDTH && mag < TRIPLE_RING) return 3*POINTS[index];
		if (mag > DOUBLE_RING-BONUS_WIDTH && mag < DOUBLE_RING) return 2*POINTS[index];
		return POINTS[index];
	}
}