We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.

You are given Q queries.

In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

Constraints

* 1≤Q≤10^5
* 1≤l_i≤r_i≤10^5
* l_i and r_i are odd.
* All input values are integers.

Input

Input is given from Standard Input in the following format:


Q
l_1 r_1
:
l_Q r_Q


Output

Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.

Examples

Input

1
3 7


Output

2


Input

4
13 13
7 11
7 11
2017 2017


Output

1
0
0
1


Input

6
1 53
13 91
37 55
19 51
73 91
13 49


Output

4
4
1
1
1
2

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static class Query{
		private int left;
		private int right;
		private int ans;

		public Query(int left, int right) {
			this.left = left;
			this.right = right;
			this.ans = 0;
		}

		public void execute(int num) {
			if(left <= num && right >= num) {
				ans++;
			}
		}

		public int getLeft() {
			return this.left;
		}

		public int getRight() {
			return this.right;
		}

		public int getAns() {
			return this.ans;
		}
	}


	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);

		int Q = in.nextInt();
		int min = 100000;
		int max = 0;

		ArrayList<Query> array = new ArrayList<Query>(Q);

		for(int i=0; i<Q; ++i) {
			int left = in.nextInt();
			int right = in.nextInt();
			array.add(new Query(left, right));
			if(min > left) {
				min = left;
			}
			if(max < right) {
				max = right;
			}
		}

		for(int i=min; i <= max; ++i) {
			if(checkLike2017(i)) {
				// System.out.println("numA: " + i + " numB: " + (i + 1) / 2);
				for(Query q : array) {
					q.execute(i);
				}
			}
		}


		for(Query q : array) {
			System.out.println(q.getAns());
		}
	}

	public static boolean checkLike2017(int numA) {
		if(numA < 3) {
			return false;
		}

		int numB = (numA + 1) / 2;
		if(checkPrimeNum(numB)) {
			return checkPrimeNum(numA);
		}else {
			return false;
		}
	}

	public static boolean checkPrimeNum(int num) {
		if(num == 2 || num == 3) {
			return true;
		}else if(num % 2 == 0 || num % 3 == 0) {
			return false;
		}

		int root = (int) Math.sqrt(num);
		for(int i=4; i<= root; ++i) {
			if(num % i == 0) {
				return false;
			}
		}

		return true;
	}

}
