#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

int main() {
	ifstream in;
	in.open("DATA5.txt");
	ofstream out;
	out.open("OUT5.txt");
	
	int n, k, i, j;

	for (i=0; i<5; i++) {
		in >> n >> k;
		j = (int)pow(2, (double)n) - 1;
		while (k>j) k-=j+1;
		if (k==j) out << "ON" << endl;
		else out << "OFF" << endl;
	}

	in.close();
	out.close();
	return 0;
}

