// Arup Guha
// 5/9/2015
// Solution to FHSPS Problem: Laser Tag

import java.util.*;

public class lasertag {

	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++) {

			// Get parameters for this case.
			int width = stdin.nextInt();
			int length = stdin.nextInt();
			int xShooter = stdin.nextInt();
			int yShooter = stdin.nextInt();
			int xTarget = stdin.nextInt();
			int yTarget = stdin.nextInt();
			double lowAngle = stdin.nextInt()*Math.PI/180;
			double highAngle = stdin.nextInt()*Math.PI/180;

			// Change in x in shot.
			int dx = xTarget - xShooter;

			// Imagine reflecting the arena over each horizontal line of symmetry,
			// over and over again, this accurately "simulates" bouncing back and
			// forth between these horizontal lines.
			double lowY = yShooter + dx*Math.tan(lowAngle);
			double highY = yShooter + dx*Math.tan(highAngle);

			// Get the first box that is less than each bound.
			int loc1 = getLocation(lowY, yTarget, length);
			int loc2 = getLocation(highY, yTarget, length);

			// Our result.
			System.out.println(loc2-loc1);
		}
	}

	public static int getLocation(double y, int yTarget, int yMax) {

		// Calculate the number of reflections and how far into
		// that "next box" you get.
		int box = (int)(y/yMax);
		double leftover = y - box*yMax;

		// Adjustment, for negative y case,
		if (leftover < -1e-9) {
			box--;
			leftover += yMax;
		}

		// Even case is like the given box.
		if (box%2 == 0) {
			if (leftover > yTarget) return box+1;
			else					return box;
		}

		// Odd case is the reflection.
		else {
			if (leftover > yMax-yTarget) return box+1;
			else						 return box;
		}

	}
}