#include <bits/stdc++.h>
#define endl "\n"
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR(x, y, z) for (int x = (y); x > (z); --x)
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define GET(a, n) for (int i = 0; i < n; ++i) cin >> a[i];
#define GETM(a, n, m) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];
#define PRINTM(a, n, m) for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) cout << a[i][j] << " ";  cout << endl; };
#define PRINT(a, n) for (int i = 0; i < n; ++i) cout << a[i] << " ";
#define LL long long
#define ULL unsigned long long
#define VI vector <int>
#define VVI vector <vector<int>>
#define PII pair <int, int>
#define GETSUM(sum, n) sum = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; sum += tmp; }
#define SUM(a, n, sum) sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; }
#define IT(a) a.begin(), a.end()
using namespace std;
template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; FOR(i, 0, n) sum += v[i]; return sum; }
struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio;

int main()
{
    int n;
    cin >> n;
    vector <string> v(n);
    FOR (i, 0, n) {
        cin >> v[i];
    }
    string s;
    cin >> s;
    int j = 0;
    int k = 0;
    int flag = 2;
    FOR (i, 0, s.size()) {
        if (flag == 2) {
            if (s[i] == '<') {
                --flag;
            }
            continue;
        }
        if (flag == 1) {
            if (s[i] == '3') {
                --flag;
            }
            continue;
        }
        if (j != v.size() && v[j][k] == s[i]) {
            ++k;
            if (k == v[j].size()) {
                k = 0;
                ++j;
                flag = 2;
            }
        }
    }
    if (!flag && j == v.size()) {
        cout << "yes";
    } else {
        cout << "no";
    }
}


#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
#define bit(a, pos) ((a >> pos) & 1)
using namespace std;
typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1-9; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(int a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[10]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;}

int main()
{
    in(n);
    string s = "<3";
    for(int i = 0; i < n; ++i)
    {
        string q;
        cin >> q;
        s += q;

    s += "<3";
    }
    string t;
    cin >> t;
    int j = 0;
    for(int i = 0; i < (int)s.length(); ++i)
    {
        while(j < (int)t.length() && s[i] != t[j])
        {
            ++j;
        }
        if (j == (int)t.length())
        {
            puts("no");
            return 0;
        }
        ++j;
    }
    puts("yes");
    return 0;
}


#include <bits/stdc++.h>
#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
#define bit(a, pos) ((a >> pos) & 1)
using namespace std;
typedef long double ld; template <class _T> inline _T sqr(const _T& x) {return x * x;} template <class _T> inline string tostr(const _T& a) {ostringstream os(""); os << a; return os.str();} const ld PI = 3.1415926535897932384626433832795L; const double EPS = 1-9; char TEMPORARY_CHAR; typedef long long ll; typedef unsigned long long ull; typedef set < int > SI; typedef vector < int > VI; typedef vector < vector < int > > VVI; typedef map < string, int > MSI; typedef pair < int, int > PII; const int INF = 1e9; inline void input(int &a) {a = 0; while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){} char neg = 0; if (TEMPORARY_CHAR == '-') {neg = 1; TEMPORARY_CHAR = getchar();} while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {a = 10 * a + TEMPORARY_CHAR - '0'; TEMPORARY_CHAR = getchar();} if (neg) a = -a;} inline void out(int a) {if (!a) putchar('0'); if (a < 0) {putchar('-'); a = -a;} char s[10]; int i; for(i = 0; a; ++i) {s[i] = '0' + a % 10; a /= 10;} ford(j, i) putchar(s[j]);} inline int nxt() {in(ret); return ret;}

int main()
{
    in(n);
    string s = "<3";
    for(int i = 0; i < n; ++i)
    {
        string q;
        cin >> q;
        s += q;
    }
    s += "<3";
    string t;
    cin >> t;
    int j = 0;
    for(int i = 0; i < (int)s.length(); ++i)
    {
        while(j < (int)t.length() && s[i] != t[j])
        {
            ++j;
        }
        if (j == (int)t.length())
        {
            puts("no");
            return 0;
        }
        ++j;
    }
    puts("yes");
    return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013-10-26 9:49:19
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 100000 + 5;

char str1[maxn], str2[maxn], s[maxn];

int main() {
    int n;
    scanf("%d", &n);
    int len = 0;
    for(int i = 0;i < n; i++) {
        scanf("%s", s);
        int l1 = strlen(s);
        for(int j = 0;j < l1; j++)
            str1[len++] = s[j];
        str1[len++] = ' ';
    }
    str1[len] = 0;
    scanf("%s", str2);
    int l2 = strlen(str2);
    int cur = 0, pp = 0;
    for(int i = 0;i < l2; i++) if(str2[i] == '<') {
        pp = 1;
    }
    else if(pp == 1 && str2[i] == '3') {
        pp = i+1;
        break;
    }
    for(int i = pp;i < l2; i++) if(str2[i] >= 'a' && str2[i] <= 'z'){
        if(str2[i] != str1[cur])
            continue;
        cur++;
        if(cur == len)  {
            break;
        }
        if(str1[cur] == ' ') {
            pp = 0;
            for(int j = i+1;j < l2; j++) if(str2[j] == '<')
                pp = 1;
            else if(str2[j] == '3' && pp == 1) {
                pp = 2;
                i = j;
                break;
            }
            if(pp == 2)
                cur++;
        }
    }
    if(cur == len)
        puts("yes");
    else
        puts("no");
    return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013-10-26 9:49:19
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 100000 + 5;

char str1[maxn], str2[maxn], s[maxn];

int main() {
    int n;
    scanf("%d", &n);
    int len = 0;
    for(int i = 0;i < n; i++) {
        scanf("%s", s);
        int l1 = strlen(s);
        for(int j = 0;j < l1; j++)
            str1[len++] = s[j];
        str1[len++] = ' ';
    }
    str1[len] = 0;
    scanf("%s", str2);
    int l2 = strlen(str2);
    int cur = 0, pp = 0;
    for(int i = 0;i < l2; i++) if(str2[i] == '<') {
        pp = 1;
    }
    else if(pp == 1 && str2[i] == '3') {
        pp = i+1;
        break;
    }
    for(int i = pp;i < l2; i++) if(str2[i] >= 'a' && str2[i] <= 'z'){
        if(str2[i] != str1[cur])
            continue;
        cur++;
        if(cur == len)  {
            break;
        }
        if(str1[cur] == ' ') {
            pp = 0;
            for(int j = i+1;j < l2; j++) if(str2[j] == '<')
                pp = 1;
            else if(str2[j] == '3' && pp == 1) {
                i = j;
                break;
            }
            cur++;
        }
    }
    if(cur == len)
        puts("yes");
    else
        puts("no");
    return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013-10-26 9:49:19
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 100000 + 5;

char str1[maxn], str2[maxn], s[maxn];
int main() {
    int n;
    scanf("%d", &n);
    int len = 0;
    for(int i = 0;i < n; i++) {
        scanf("%s", s);
        int l1 = strlen(s);
        for(int j = 0;j < l1; j++)
            str1[len++] = s[j];
    }
    str1[len] = 0;
    scanf("%s", str2);
    int l2 = strlen(str2);
    int cur = 0;
    bool flag = 1;
    for(int i = 0;i < l2; i++) if(str2[i] >= 'a' && str2[i] <= 'z'){
        if(str2[i] != str1[cur]) {
            flag = 0;
            break;
        }
        cur++;
    }
    if(cur != len)  flag = 0;
    if(!flag)   puts("no");
    else    puts("yes");
    return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013-10-26 9:49:19
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 100000 + 5;

char str1[maxn], str2[maxn], s[maxn];
int main() {
    int n;
    scanf("%d", &n);
    int len = 0;
    for(int i = 0;i < n; i++) {
        scanf("%s", s);
        int l1 = strlen(s);
        for(int j = 0;j < l1; j++)
            str1[len++] = s[j];
    }
    str1[len] = 0;
    scanf("%s", str2);
    int l2 = strlen(str2);
    int cur = 0;
    bool flag = 1;
    for(int i = 0;i < l2; i++) if(str2[i] >= 'a' && str2[i] <= 'z'){
        if(str2[i] == str1[cur]) {
            cur++;
        }
        if(cur == len)  break;
    }
    if(cur != len)  flag = 0;
    if(!flag)   puts("no");
    else    puts("yes");
    return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013-10-26 9:49:19
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 200000 + 5;

char str1[maxn], str2[maxn], s[maxn];

int main() {
    int n;
    scanf("%d", &n);
    int len = 0;
    for(int i = 0;i < n; i++) {
        scanf("%s", s);
        int l1 = strlen(s);
        for(int j = 0;j < l1; j++)
            str1[len++] = s[j];
        str1[len++] = ' ';
    }
    str1[len] = 0;
    scanf("%s", str2);
    int l2 = strlen(str2);
    int cur = 0, pp = 0;
    for(int i = 0;i < l2; i++) if(str2[i] == '<') {
        pp = 1;
    }
    else if(pp == 1 && str2[i] == '3') {
        pp = i+1;
        break;
    }
    for(int i = pp;i < l2; i++) if(str2[i] >= 'a' && str2[i] <= 'z'){
        if(str2[i] != str1[cur])
            continue;
        cur++;
        if(cur == len)  {
            break;
        }
        if(str1[cur] == ' ') {
            pp = 0;
            for(int j = i+1;j < l2; j++) if(str2[j] == '<')
                pp = 1;
            else if(str2[j] == '3' && pp == 1) {
                pp = 2;
                i = j;
                break;
            }
            if(pp == 2)
                cur++;
        }
    }
    if(cur == len)
        puts("yes");
    else
        puts("no");
    return 0;
}


/* **********************************************
Author      : JayYe
Created Time: 2013-10-26 9:49:19
File Name   : JayYe.cpp
*********************************************** */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

const int maxn = 100000 + 5;

char str1[maxn], str2[maxn], s[maxn];

int main() {
    int n;
    scanf("%d", &n);
    int len = 0;
    for(int i = 0;i < n; i++) {
        scanf("%s", s);
        int l1 = strlen(s);
        for(int j = 0;j < l1; j++)
            str1[len++] = s[j];
        str1[len++] = ' ';
    }
    str1[len] = 0;
    scanf("%s", str2);
    int l2 = strlen(str2);
    int cur = 0, pp = 0;
    for(int i = 0;i < l2; i++) if(str2[i] == '<') {
        pp = 1;
    }
    else if(pp == 1 && str2[i] == '3') {
        pp = i+1;
        break;
    }
    for(int i = pp;i < l2; i++) if(str2[i] >= 'a' && str2[i] <= 'z'){
        if(str2[i] != str1[cur])
            continue;
        cur++;
        if(str1[cur] == ' ') {
            pp = 0;
            for(int j = i+1;j < l2; j++) if(str2[j] == '<')
                pp = 1;
            else if(str2[j] == '3' && pp == 1) {
                i = j;
                break;
            }
            cur++;
        }
        if(cur == len)  {
            break;
        }
    }
    if(cur == len)
        puts("yes");
    else
        puts("no");
    return 0;
}


// *** ADDED BY HEADER FIXUP ***
#include <string>
// *** END ***
// *** ADDED BY HEADER FIXUP ***
#include <algorithm>
#include <iostream>
#include <vector>
// *** END ***
//#include<iostream>
typedef long long ll;
using namespace std;
int a[1000*1000+44];
string tt="";
string gogo="";
size_t cc=0;
int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    tt="<3";
    for(int i = 0;i<n;++i){
        string tmp;
        cin>>tmp;
        tt+=tmp;
        tt+="<3";
    }
    cin>>gogo;
    for(size_t i = 0;i<gogo.size();++i){
        if(cc<tt.size()&&gogo[i]==tt[cc]) cc++;
    }
    if((size_t)cc==tt.size()) cout<<"yes";
    else cout<<"no";
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

bool check(string b, vector<string> a)
{
    //cout<<a[0]<<" "<<b<<endl;
    int i;
    string s="<3";
    if(a.size() == 0)
        return true;

    for(i=0; i<a.size(); i++)
    {
        s+=a[i];
        s = s+"<3";
    }
   //cout<<s<<endl;
   //cout<<b<<endl;
   if(s.size() > b.size())
    return false;

   int j=0;
    i = 0;
   while( i<s.size())
   {
       if(j == b.size() )
       {
            //cout<<"gg"<<i<<endl;
            return false;
       }

       if(s.at(i) == b.at(j))
       {
           //cout<<i<<" "<<j<<" "<<s.size()<<" "<<b.size()<<endl;
           j++;
           i++;
       }
       else
        j++;
   }
   return true;
}
int main()
{
    int n;
    cin>>n;

    int i;
    vector<string> v;
    for(i=0; i<n; i++)
    {
        string a;
        cin>>a;
        v.push_back(a);
    }

    string b;
    cin>>b;

    if(check(b,v)) cout<<"yes"; else cout<<"no";
    return 0;
}


for _ in range(int(input())):
    n,m,a,b = map(int,input().split())
    if a > n / 2:
        a = n - a - 1
    if b > m / 2:
        b = m - b - 1
    if (n - a - 1) * m >= (m - b - 1) * n:
        print((n - a - 1) * m)
    else:
        print((m - b - 1) * n)


for _ in range(int(input())):
    n,m,a,b = map(int,input().split())
    if n == 1 and m == 1:
        print(0)
        continue
    if a > n / 2:
        a = n - a - 1
    if b > m / 2:
        b = m - b - 1
    if (n - a - 1) * m >= (m - b - 1) * n:
        print((n - a - 1) * m)
    else:
        print((m - b - 1) * n)


for i in range(int(input())):
	a,b,c,d=map(int,input().split())
	# a,b,c,d=l
	n=max(a-c-1,c)
	m=max(b-d-1,d)
	if(n==0):
		n=1
	if(m==0):
		m=1
	if(n==1 or m==1):
		print(m*n)
	else:
		print(max(n*b,m*a))


for i in range(int(input())):
	a,b,c,d=map(int,input().split())
	# a,b,c,d=l
	n=max(a-c-1,c)
	m=max(b-d-1,d)
	print(max(d*a,c*b,n*b,m*a))


for i in range(int(input())):
	a,b,c,d=map(int,input().split())
	n=max(a-c-1,c)
	m=max(b-d-1,d)
	if(n==0):
		n=1
	if(m==0):
		m=1
	if(n==1 or m==1):
		print(m*n)
	else:
		print(max(n*b,m*a))


t = int(input())

while t:

    a, b, x, y = map(int, input().split())

    left = x*b;
    right = (a - 1 - x) * b
    up = a * y
    down = (b - 1 - y) * a

    print(max(max(left, right), max(up, down)))

    t -= 1


t = int(input())

def somaUnica(sum):
    if len(set(sum)) == len(sum):
        return True
    else:
        return False

def zipSum(a,b):
    sum = [r + s for r, s in zip(a, b)]
    if somaUnica(sum):
        print(*a)
        print(*b)
        return True

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    if zipSum(a,b):
        continue

    a.sort()
    if zipSum(a,b):
        continue

    b.sort()
    if zipSum(a, b):
        continue

    a.sort(reverse=True)
    if zipSum(a,b):
        continue


t = int(input())
for _ in range(t):
    area = 0
    inpt = input()
    num = list(map(int, inpt.split()))
    a = num[0]
    b = num[1]
    x = num[2]
    y = num[3]

    if x == y:
        area = (a-1)*b

    else:
        if(x > 0  and y > 0 and (x%y == 0 or y%x == 0)):
            r = max(a - x, x)
            s = max(b - y, y)
        else:
            r = max(a - x-1, x-1)
            s = max(b - y-1, y-1)

        area = max(s*a, r*b)

    print(area)


t = int(input())
for _ in range(t):
    area = 0
    inpt = input()
    num = list(map(int, inpt.split()))
    a = num[0]
    b = num[1]
    x = num[2]
    y = num[3]

    if ((a - x - 1) * b) >= ((b - y - 1) * a) and ((a - x - 1) * b) >= (a * y) and ((a - x - 1) * b) >= (b * x):
        print((a - x - 1) * b)
        continue
    elif ((b - y - 1) * a) >= ((a - x - 1) * b) and ((b - y - 1) * a) >= (a * y) and ((b - y - 1) * a) >= (b * x):
        print((b - y - 1) * a)
        continue
    elif (a * y) >= (a - x - 1) * b and (a * y) >= (b - y - 1) * a and (a * y) >= (b * x):
        print(a * y)
        continue
    else:
        print(b * x)
        continue


for _ in range(int(input())) :
    a,b,x,y = map(int,input().split())
    m = ((b-1)-y)*a
    n = (y*a)
    p = ((a-1)-x)*b
    q = (x*b)
    ans = max(m,n,p,q)
    print(ans)


for _ in range(int(input())) :
    a,b,x,y = map(int,input().split())
    m = ((b-1)-y)*a
    n = (y*a)
    ans = max(m,n)
    if ans == 0 :
        print(1)
    else :
        print(ans)


for i in range(int(input())):
    a, b, x, y = map(int, input().split())
    print(max(max(x, a - x - 1) * b, max(y, b - y - 1) * a))

#help from _IchBin_


t=int(input())
for i in range(t):
    ar=list(map(int,input().rstrip().split()))
    x=ar[2]+1
    y=ar[3]+1
    a=ar[0]
    b=ar[1]
    maxarea=(a-x)*(b)
    area=(y-1)*a
    if area>maxarea:maxarea=area
    area=(x-1)*b
    if area>maxarea:maxarea=area
    area=a*(b-y)
    if area>maxarea:maxarea=area
    print(maxarea)


t = int(input("The number of tests is : "))
solutions = []
for i in range(t) :
    string = str(input("Dates : "))
    st = string.split()
    a = int(st[0])
    b = int(st[1])
    x = int(st[2])
    y = int(st[3])
    case1 = (b-y-1)*a
    case2 = y*a
    case3 = x*b
    case4 = (a-x-1)*b
    case = max(case1, case2, case3, case4)
    solutions.append(case)
for solution in solutions :
    print(solution)


t = int(input())
solutions = []
for i in range(t) :
    string = str(input())
    st = string.split()
    a = int(st[0])
    b = int(st[1])
    x = int(st[2])
    y = int(st[3])
    case1 = (b-y-1)*a
    case2 = y*a
    case3 = x*b
    case4 = (a-x-1)*b
    case = max(case1, case2, case3, case4)
    solutions.append(case)
for solution in solutions :
    print(solution)


t = int(input("The number of tests is : "))
for i in range(t) :
    string = str(input("Dates : "))
    st = string.split()
    a = int(st[0])
    b = int(st[1])
    x = int(st[2])
    y = int(st[3])
    case1 = (b-y-1)*a
    case2 = y*a
    case3 = x*b
    case4 = (a-x-1)*b
    case = max(case1, case2, case3, case4)
    print(case)


t = int(input())
matrix = []
def checkTop(a, y):
    base = 0
    height = 0
    if (y != 0):
        height += y
        base += a
    return base * height

def checkRight(a, b, x):
    base = 0
    height = 0
    if (x != a):
        base +=(a-1)-x
        height += b
    return base * height

def checkBottom(a, b, y):
    base = 0
    height = 0
    if (y != b):
        height += (b-1)-y
        base += a
    return base * height

def checkLeft(b, x):
    base = 0
    height = 0
    if (x != 0):
        base += x
        height +=b
    return base * height

if 1 <= t <= 10 ** 4:
    for i in range(0, t):
        distance = tuple(input().split())
        a = int(distance[0])
        b = int(distance[1])
        x = int(distance[2])
        y = int(distance[3])
        areas = [checkTop(a, y), checkRight(a, b, x), checkBottom(a, b, y), checkLeft(b,x)]
        print(max(areas))


t = int(input())
matrix = []

def checkTop(b, x):
    base = 0
    height = 0
    if (x != 0):
        for i in range(0, x):
            height += 1
        for j in range(0, b):
            base += 1
    return base * height

def checkRight(a, b, y):
    base = 0
    height = 0
    if (y != b):
        for i in range(y + 1, b):
            base += 1
        for j in range(0, a):
            height += 1
    return base * height

def checkBottom(a, b, x):
    base = 0
    height = 0
    if (x != a):
        for i in range(0, b):
            base += 1
        for j in range(x + 1, a):
            height += 1
    return base * height

def checkLeft(a, y):
    base = 0
    height = 0
    if (y != 0):
        for i in range(0, y):
            base += 1
        for j in range(0, a):
            height += 1
    return base * height

if 1 <= t <= 10 ** 4:
    for i in range(0, t):
        distance = tuple(input().split())
        a = int(distance[0])
        b = int(distance[1])
        x = int(distance[2])
        y = int(distance[3])
        for rows in range(0, a):
            matrix.append([])
            for cols in range(0, b):
                matrix[rows].append(0)
        areas = [checkTop(b, x), checkRight(a, b, y), checkBottom(a, b, x), checkLeft(a,y)]
        print(max(areas))


t = int(input())
matrix = []

def checkTop(b, x):
    base = 0
    height = 0
    if (x != 0):
        for i in range(0, x):
            height += 1
        for j in range(0, b):
            base += 1
    return base * height

def checkRight(a, b, y):
    base = 0
    height = 0
    if (y != b):
        for i in range(y + 1, b):
            base += 1
        for j in range(0, a):
            height += 1
    return base * height

def checkBottom(a, b, x):
    base = 0
    height = 0
    if (x != a):
        for i in range(0, b):
            base += 1
        for j in range(x + 1, a):
            height += 1
    return base * height

def checkLeft(a, y):
    base = 0
    height = 0
    if (y != 0):
        for i in range(0, y):
            base += 1
        for j in range(0, a):
            height += 1
    return base * height

if 1 <= t <= 10 ** 4:
    for i in range(0, t):
        distance = tuple(input().split())
        a = int(distance[0])
        b = int(distance[1])
        x = int(distance[2])
        y = int(distance[3])
        areas = [checkTop(b, x), checkRight(a, b, y), checkBottom(a, b, x), checkLeft(a,y)]
        print(max(areas))


test_cases = int(input())
for test in range(test_cases):
	w, l, x, y = input().split()
	w = int(w)
	l = int(l)
	x = int(x)
	y = int(y)
	width_choice = max(w - x - 1, x - 0)
	length_choice = max(l - y - 1, y - 0)
	if width_choice > length_choice:
		print(width_choice * l)
	else:
		print(length_choice * w)


test_cases = int(input())
for test in range(test_cases):
	w, l, x, y = input().split()
	w = int(w)
	l = int(l)
	x = int(x)
	y = int(y)
	width_choice = max(w - x - 1, x - 0)
	length_choice = max(l - y - 1, y - 0)
	best_area = max(width_choice * l, length_choice * w)
	print(best_area)


t=int(input())

for n in range(1,t+1):
    list=[]

for n in range(1,t+1):
    a,b,x,y = input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    list.append(max((x-1)*b, (a-x-1)*b, a*(y-1), a*(b-y-1)))

for n in list:
    print(n)


t=int(input())

for n in range(1,t+1):
    list=[]

for n in range(1,t+1):
    a,b,x,y = input().split()
    x=int(x)
    y=int(y)
    a=int(a)
    b=int(b)
    list.append(max(x*b, (a-x-1)*b, a*(y), a*(b-y-1)))

for n in list:
    print(n)


t = int(input())

for i in range(t):
    ti = list(map(int, input().split()))
    out1 = (ti[0]-ti[2]-1)*ti[1]
    out2 = (ti[1]-ti[3]-1)*ti[0]
    out3 = ti[0]*ti[3]
    out4 = ti[1]*ti[2]
    print(max(out1,out2,out3, out4))


t = int(input())

for i in range(t):
    ti = list(map(int, input().split()))
    out1 = (ti[0]-ti[2]-1)*ti[1]
    out2 = (ti[1]-ti[3]-1)*ti[0]
    out3 = ti[0]*ti[3]
    print(max(out1,out2,out3))


d=int(input())
n1=0
n2=0
n3=0
n4=0
for i in range (d):
    a,b,c,v=map(int,input().split())
    n1=a*v
    n2=a*(b-v-1)
    n3=b*(a-c-1)
    n4=b*c
    if n1>n2:
        s1=n1
    else :
        s1=n2
    if n3>n4 :
        s2=n3
    else :
        s2=n4
    if s1> s2 :
        print(s1)
    else :
        print(s2)


t=int(input())
while t>0:
    a,b,x,y=int(input().split())
    temp=b*x
    ans=temp
    ans=b*(a-x-1)
    ans=max(ans,temp)
    temp=a*y
    ans=max(ans,temp)
    ans=a*(b-y-1)
    ans=max(ans,temp)
    print(ans)
    t=t-1


t=int(input())
while t>0:
    a, b, x, y = [int(a) for a in input().split()]
    print(max(max(y * a, x * b), max((a - (x + 1)) * b, (b - (y + 1)) * a)))
    t=t-1


t=int(input())
while t>0:
    a, b, x, y = [int(a) for a in input().split()]
    temp=b*x
    ans=temp
    ans=b*(a-x-1)
    ans=max(ans,temp)
    temp=a*y
    ans=max(ans,temp)
    ans=a*(b-y-1)
    ans=max(ans,temp)
    print(ans)
    t=t-1


ilosc = int(input())
tab = []
for i in range(ilosc):
    a=int(input())
    b=int(input())
    xa=int(input())
    xb=int(input())
    tab.append((max((a-(xa+1))*b , xb*a , xa*b , (b-(xb+1)*a))))
for j in range(len(tab)):
    print( "\n" , tab[j])


ilosc = int(input())
tab = []
for i in range(ilosc):
    a, b, xa, xb = [int(x) for x in input().split()]
    tab.append(max((a-(xa+1))*b , xb*a , xa*b , (b-(xb+1))*a))
for j in range(len(tab)):
    print( "\n" , tab[j])


ilosc = int(input())
tab = []
for i in range(ilosc):
    a=int(input())
    b=int(input())
    xa=int(input())
    xb=int(input())
    tab.append(max((a-(xa+1))*b , xb*a , xa*b , (b-(xb+1))*a))
for j in range(len(tab)):
    print( "\n" , tab[j])


for i in range(int(input())):
	a,b,m,n=map(int,input().split())
	print(max(a*n,a*(b-1-n),b*m,b*(a-1-m)))


n = int(input())

for i in range(n):
    a, b, x, y = map(int, input().split())
    h = max(x, a - x)
    if x > a-x:
        h += 1
    v = max(y, b - y)
    if y > b - y:
        v += 1
    print(max((h-1)*b, (v-1)*a))


n = int(input())

for i in range(n):
    a, b, x, y = map(int, input().split())
    x += 1
    y += 1

    print(max((a - x) * b, (x-1) * b, (b-y) * a, (y-1) * a))


for o in range(int(input())):
    a,b,x,y = map(int ,input().split())
    a1 = a*max(y,b-y-1)
    a2 = b*max(x,a-x-1)
    print(max(a1,a2))


for o in range(int(input())):
    a,b,x,y = map(int , input().split())
    if b==1:
        a = (a-3) +1
        print(a*b)
    else:
        if abs(b-y)>y:
            print((b-y-1)*a)
        else:
            print(b*a)


for o in range(int(input())):
    a,b,x,y = map(int , input().split())
    if b==1:
        if x==0 and y==0:
            print((a-1)*b)
        else:
            if a-y>y:
                print((a-y-1)*b)
            else:
                print(y*b)
    else:
        if y>=x:
            if abs(b-y)>y:
                print((b-y-1)*a)
            else:
                print(b*a)
        else:
            if a-x>y:
                print((a-x-1)*b)
            else:
                print(x*b)


for o in range(int(input())):
    a,b,x,y = map(int , input().split())
    if b==1:
        if x==0 and y==0:
            print((a-1)*b)
        else:
            if a-x>x:
                print((a-x-1)*b)
            else:
                print(x*b)
    else:
        if abs(b-y)>y:
            print((b-y-1)*a)
        else:
            print(b*a)


for o in range(int(input())):
    a,b,x,y = map(int , input().split())
    if b==1:
        if x==0 and y==0:
            print((a-1)*b)
        else:
            if a-y>y:
                print((a-y-1)*b)
            else:
                print(y*b)
    else:
        if abs(b-y)>y:
            print((b-y-1)*a)
        else:
            print(y*a)


##############--->>>>> Deepcoder Amit Kumar Bhuyan <<<<<---##############

"""
 Perfection is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
"""
from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li():  return list(mi())

def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial,cos,tan,sin,radians
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *
#import threading
#from itertools import permutations
#Copy 2D list  m = [x[:] for x in mark] .. Avoid Using Deepcopy
import sys
input = sys.stdin.readline
scanner = lambda: int(input())
string = lambda: input().rstrip()
get_list = lambda: list(read())
read = lambda: map(int, input().split())
get_float = lambda: map(float, input().split())
# from bisect import bisect_left as lower_bound;
# from bisect import bisect_right as upper_bound;
# from math import ceil, factorial;

def ceil(x):
    if x != int(x):
        x = int(x) + 1
    return x

def factorial(x, m):
	val = 1
	while x>0:
		val = (val * x) % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

# swap_array function
def swaparr(arr, a,b):
    temp = arr[a];
    arr[a] = arr[b];
    arr[b] = temp;

## gcd function
def gcd(a,b):
    if b == 0:
        return a;
    return gcd(b, a % b);

## lcm function
def lcm(a, b):
	return (a * b) // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

## nCr function efficient using Binomial Cofficient
def nCr(n, k):
	if k > n:
		return 0
	if(k > n - k):
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res) % MOD

## alternative
def comb(n,x):
    a,b=1,1
    for i in range(1,x+1):
        a*=(n+1-i)
        b*=i
    return (a//b)%MOD

## upper bound function code -- such that e in a[:i] e < x;

## prime factorization
def primefs(n):
    ## if n == 1    ## calculating primes
    primes = {}
    while(n%2 == 0 and n > 0):
        primes[2] = primes.get(2, 0) + 1
        n = n//2
    for i in range(3, int(n**0.5)+2, 2):
        while(n%i == 0 and n > 0):
            primes[i] = primes.get(i, 0) + 1
            n = n//i
    if n > 2:
        primes[n] = primes.get(n, 0) + 1
    ## prime factoriazation of n is stored in dictionary
    ## primes and can be accesed. O(sqrt n)
    return primes

## MODULAR EXPONENTIATION FUNCTION
def power(x, y, p):
    if y == 0:
        return 1
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res

## DISJOINT SET UNINON FUNCTIONS
def swap(a,b):
    temp = a
    a = b
    b = temp
    return a,b;

# find function with path compression included (recursive)
# def find(x, link):
#     if link[x] == x:
#         return x
#     link[x] = find(link[x], link);
#     return link[x];

# find function with path compression (ITERATIVE)
def find(x, link):
    p = x;
    while( p != link[p]):
        p = link[p];

    while( x != p):
        nex = link[x];
        link[x] = p;
        x = nex;
    return p;

# the union function which makes union(x,y)
# of two nodes x and y
def union(x, y, link, size):
    x = find(x, link)
    y = find(y, link)
    if size[x] < size[y]:
        x,y = swap(x,y)
    if x != y:
        size[x] += size[y]
        link[y] = x

## returns an array of boolean if primes or not USING SIEVE OF ERATOSTHANES
def sieve(n):
    prime = [True for i in range(n+1)]
    prime[0], prime[1] = False, False
    p = 2
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1
    return prime

# Euler's Toitent Function phi
def phi(n) :

    result = n
    p = 2
    while(p * p<= n) :
        if (n % p == 0) :
            while (n % p == 0) :
                n = n // p
            result = result * (1.0 - (1.0 / (float) (p)))
        p = p + 1
    if (n > 1) :
        result = result * (1.0 - (1.0 / (float)(n)))

    return (int)(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False

	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n

#### PRIME FACTORIZATION IN O(log n) using Sieve ####
MAXN = int(1e5 + 5)
def spf_sieve():
    spf[1] = 1;
    for i in range(2, MAXN):
        spf[i] = i;
    for i in range(4, MAXN, 2):
        spf[i] = 2;
    for i in range(3, ceil(MAXN ** 0.5), 2):
        if spf[i] == i:
            for j in range(i*i, MAXN, i):
                if spf[j] == j:
                    spf[j] = i;
    ## function for storing smallest prime factors (spf) in the array

################## un-comment below 2 lines when using factorization #################
spf = [0 for i in range(MAXN)]
# spf_sieve();
def factoriazation(x):
    res = []
    for i in range(2, int(x ** 0.5) + 1):
    	while x % i == 0:
    		res.append(i)
    		x //= i
    if x != 1:
   		res.append(x)
    return res
    ## this function is useful for multiple queries only, o/w use
    ## primefs function above. complexity O(log n)

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

## taking integer array input
def int_array():
    return list(map(int, input().strip().split()));

def float_array():
    return list(map(float, input().strip().split()));

## taking string array input
def str_array():
    return input().strip().split();

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		# print(low, mid, high)
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

## for checking any conditions
def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

## for sorting according to second position
def sortSecond(val):
	return val[1]

#defining a couple constants
MOD = int(1e9)+7;
CMOD = 998244353;
INF = float('inf'); NINF = -float('inf');
small = "abcdefghijklmnopqrstuvwxyz"
large = small.upper()

################### ---------------- TEMPLATE ENDS HERE ---------------- ###################

from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal
# from sys import stdout
# import numpy as np
"""
_______________
rough work here
_______________

n buildings in a straight line
cities security serive discovered that
some buildings were mined.
A map was compiled, which is a string of length n,
where ith character is '1'
"""

def interact(x, y):
	print("?", x + 1, y + 1)
	space = input()
	sys.stdout.flush()
	return int(input())

def solve():
    a, b, x, y = read()
    case1 = x * b
    case2 = a * y
    case3 = (a - x - 1) * b
    case4 = a * (b - y - 1)
    print(max(max(case1, case2), max(case3, case4)))

# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    # sys.stdin = open("input.txt", "r")
    # sys.stdout = open("output.txt", "w")
    t = scanner()
    for i in range(t):
    	solve()
    #dmain()

# Comment Read()
	# fin_time = datetime.now()
# 	print("Execution time (for loop): ", (fin_time-init_time))


for i in range(int(input())):
	a,b,x,y=list(map(int,input().split()))
	if b==1:
		print(max(((a-1)-x)*b,x*b))
	else:
		print(max(((b-1)-y)*a,y*a))


for i in range(int(input())):
	a,b,x,y=list(map(int,input().split()))
	if b>=a:
		print(max(((b-1)-y)*a,y*a))
	else:
		print(max(((a-1)-x)*b,x*b))


for i in range(int(input())):
	a,b,x,y=list(map(int,input().split()))
	col=max(((a-1)-x)*b,x*b)
	row=max(((b-1)-y)*a,y*a)
	print(max(row,col))


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

# sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")

def main():
    t = I()

    rr = []
    for _ in range(t):
        a,b,x,y = LI()

        r = max(a * max(y, b-y-1), b * max(x, a-x-1))
        rr.append(r)

    return JA(rr, "\n")

print(main())


import sys
input = sys.stdin.readline
for ti in range(int(input())):
    a, b, x, y = [int(x) for x in input().strip().split()]
    print(max((x)*(b), (a)*(y), (a-x-1)*(b), (a)*(b-y-1)))


#import sys
for ti in range(int(input())):
    a, b, x, y = [int(x) for x in input().strip().split()]
    print(max((x)*(b), (a)*(y), (a-x-1)*(b), (a)*(b-y-1)))


t = int(input())
#t = 1

for i in range(t):
	l = list(map(int, input().split()))
	#l = [2, 1, 0, 0]
	length = max(l[0] - l[2] - 1, l[2])
	breadth = max(l[1] - l[3] - 1, l[3])
	print(max(length*l[1], breadth*l[0]))


t = int(input())

for i in range(t):
	l = list(map(int, input().split()))
	print(max(l[2], l[0] - l[2] - 1)*max(l[3], l[1] - l[3] - 1))


testCase = int(input())
for i1 in range(testCase):
    parameters = list(map(int, input().split()))
    parameters[0] -= 1
    parameters[1] -= 1
    area = [0]*4
    area[0] = (parameters[0] + 1)*(parameters[1]-parameters[3])
    area[1] = (parameters[0] + 1)*(parameters[3])
    area[2] = (parameters[1] + 1)*(parameters[0]-parameters[2])
    area[3] = (parameters[1] + 1)*(parameters[2])
    print(max(area))


testCase = int(input())
for i1 in range(testCase):
    parameters = list(map(int, input().split()))
    parameters[0] -= 1
    parameters[1] -= 1
    area = [0]*4
    area[0] = (parameters[0] + 1)*(parameters[1]-parameters[3])
    area[1] = (parameters[0] + 1)*(parameters[3])
    area[2] = (parameters[1] + 1)*(parameters[0]-parameters[2])
    area[3] = (parameters[1] + 1)*(parameters[2])

    print(max(area))


for i in range(int(input())):
    a,b,x,y=map(int,input().split())
    if x+y==0:print(a*b-b)
    else:
        if b/2>y:print(a*(b-y-1))
        else:print(a*b - a*(b-y))


for i in range(int(input())):
    a,b,x,y=map(int,input().split())
    l=x*b
    r=b*(a-x-1)
    u=a*(b-y-1)
    d=a*y
    print(max(max(u,d),max(l,r)))


for ctr in range(int(input())):
	a,b,x,y=map(int,input().split())
	print(max(max(x,a-1-x)*b,a*max(y,b-1-y)))


for ctr in range(int(input())):
	a,b,x,y=map(int,input().split())
	print(max(max(x,a−1−x)*b,a*max(y,b−1−y))


T = gets.to_i

T.times do
  a, b, x, y = gets.split.map(&:to_i)

  a1 = a * y
  a2 = a * (b - y - 1)
  a3 = b * x
  a4 = b * (a - x - 1)

  puts [a1, a2, a3, a4].max
end


a = input()
for i in range(a):
    b = list(map(int,raw_input().split()))
    q = []
    #yataylar
    q.append(b[2] * b[1])
    q.append(((b[0]-1)-b[2])*b[1])
    #dikeyler
    q.append(b[3] * b[0])
    q.append(((b[1] - 1)-b[3]) * b[0])
    print max(q)


#!/usr/bin/env python

from sys import stdin, stderr

def solve(a, b, x, y):
   return max( x * b, (a - x - 1) * b, a * y, a * (b - y - 1) )

def main():
   TC = int(stdin.readline())
   for tc in xrange(TC):
      a, b, x, y = map(int, stdin.readline().split())
      res = solve(a, b, x, y)
      print(res)

   return 0

if __name__ == '__main__': main()


from collections import defaultdict as dd, Counter, OrderedDict as od, deque
from itertools import combinations as comb, permutations as perm
from functools import reduce
from math import log, ceil, floor
from fractions import gcd

import os, sys

#sys.stdin = open("pa.txt", "r")
raw_input = sys.stdin.readline

int_input = lambda : int(raw_input())
list_input = lambda : list(raw_input().strip())
explode_input = lambda sep :raw_input().split(sep)
format_input = lambda object : map(object, raw_input().split())

t = int_input()
for t_itr in xrange(t):
	a, b, x, y = format_input(int)

	a, b = a - 1, b - 1
	print(max([x * (b + 1), (a - (x + 1) + 1)* (b + 1), (a + 1) * y, (a + 1)*(b - (y + 1) + 1)]))


import math
from sys import stdin as c

n=int(input())
a=[]
for i in range(n):
	a.append(c.readline())
a=list(map(lambda x:list(map(int,x.split(' '))),a))
for i in a:
	print(max(i[0]*i[3],i[1]*i[2],(i[0]-i[2]-1)*i[1],(i[1]-i[3]-1)*i[0]))


test = input()
for x in xrange(test):
    x,y,dx,dy = map(int,raw_input().split())
    left = dx*y
    bottom = (x - 1 - dx)*y
    right = (y - 1 - dy)*x
    top = dy*x
    print max(top,left,right,bottom)


t = input()
for tc in range(t):
	a,b,x,y = [int(r) for r in raw_input().split(" ")]
	ar1 = b * (a-x-1)
	ar2 = b * x
	ar3 = a * (b-y-1)
	ar4 = a * y
	ans = max([ar1,ar2,ar3,ar4])
	print ans


def func(a, b, x, y):
    a1, a2 = x, a - 1 - x
    b1, b2 = y, b - 1 - y
    return max(a1 * b, a2 * b, a * b1, a * b2)

n = int(input())
for i in range(n):
    a, b, x, y = list(map(int, input().split(' ')))
    ans = func(a, b, x, y)
    print ans


def func(a, b, x, y):
    a1, a2 = x, a - 1 - x
    b1, b2 = y, b - 1 - y
    return max(a1 * b, a2 * b, a * b1, a * b2)

n = int(input())
for i in range(n):
    a, b, x, y = list(map(int, raw_input().split(' ')))
    ans = func(a, b, x, y)
    print ans


import math
import heapq
import sys
num = int(raw_input())
for i in range(num):
    a = [int(x) for x in raw_input().split(" ")]
    ans = max(a[1]*a[2], (a[0]-a[2]-1)*a[1], a[3]*a[0], (a[1]-a[3]-1)*a[0])
    print(ans)


for _ in range(input()):
    a,b,x,y=[int(i) for i in raw_input().split()]
    print max(x*b,(a-x-1)*b,y*a,(b-y-1)*a)


for _ in range(input()):
	a, b, x, y = map(int,raw_input().split())
	print max( max(x*b, (a-1-x)*b ), max(y*a, (b-1-y)*a )  )


t = int(raw_input().strip())
for case in range(t):
  a, b, x, y = map(int, raw_input().strip().split(" "))

  s1 = a * max(y, b - y - 1)
  s2 = b * max(x, a - x - 1)
  print max(s1, s2)


for _ in xrange(int(raw_input())):
    a, b, x, y =  map(int, raw_input().split())
    r1 = a * y
    r2 = b * x
    r3 = a * (b - y - 1)
    r4 = b * (a - x - 1)
    print max(r1, r2, r3, r4)


#include <stdio.h>
int main()
{
	int t,x,y,a,b,c,d,ans,ans1;
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d%d",&a,&b,&x,&y);
		c=a-x;
		d=b-y;
		if(x<c)
			x=c-1;
		if(y<d)
			y=d-1;
		ans=a*y;
		ans1=b*x;
		printf("%d\n",(ans>ans1)?ans:ans1);
	}
}


#include<stdio.h>
int main()
{
    long long int a,b,x,y,test,loop;
    scanf("%lld",&test);
    for(loop=0;loop<test;loop++)
    {
        scanf("%lld%lld%lld%lld",&a,&b,&x,&y);
        x++;
        y++;
        if(x<=a/2)
        {
            printf("%lld\n",(a-x)*b);
        }
        else printf("%lld\n",(x-1)*b);
    }
}


#include<stdio.h>
#include<math.h>
#define ll unsigned long long int

ll main(){
	ll a, b, x, y, t, max_area, i;
    ll arr[4];
	scanf("%llu", &t);

	while(t--)
    {
        scanf("%llu %llu %llu %llu", &a, &b, &x, &y);

        max_area = a * y;
        arr[1] = (a-x -1)*b;
        arr[2] = a*(b-y-1);
        arr[3] = b*x;

        for(i = 1; i < 3; i++)
        {
            if(arr[i] > max_area)
                max_area = arr[i];
        }

        printf("%llu\n", max_area);
    }
}


#include<stdio.h>
#include<math.h>
#define ll unsigned long long int

ll main(){
	ll a, b, x, y, t, max_area, i;
    ll arr[4];
	scanf("%llu", &t);

	while(t--)
    {
        scanf("%llu %llu %llu %llu", &a, &b, &x, &y);

        max_area = a * y;
        arr[1] = (a-x -1)*b;
        arr[2] = a*(b-y-1);
        arr[3] = b*x;

        for(i = 1; i <= 3; i++)
        {
            if(arr[i] > max_area)
                max_area = arr[i];
        }

        printf("%llu\n", max_area);
    }
}


#include <stdio.h>

int main()
{
	int t,x,y,a,b,c,d,ans;
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d%d",&a,&b,&x,&y);
		c=a-x;
		d=b-y;
		if(x<c)
			x=c-1;
		if(y<d)
			y=d-1;
		if(x>y)
			ans=b*x;
		if(y>x)
			ans=a*y;
		if(y==x){
			if(a>b)
				ans=a*y;
			else
				ans=b*x;
		}
		printf("%d\n",ans);
	}
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int a, b, x, y, n;
    int new_a, new_b;
    scanf("%d\n", &n);
    while (n > 0){
        scanf("%d %d %d %d", &a, &b, &x, &y);
        new_a = ((a - 1 - x) > x) ? (a - 1 - x) : x;
        new_b = ((b - 1 - y) > y) ? (b - 1 - y) : y;
        if (new_a * b > new_b * a)
            printf("%d\n", new_a * b);
        else
            printf("%d\n", new_b * a);
        n--;
    }
}


#include <stdio.h>

int t, x1, x2, y1, y2, d, pix, i;

int main()
{
	scanf("%d", &t);
	for(i=1; i<=t; i++)
	{
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		d=x2; pix=d*y1;
		d=x1-x2-1; if(d*y1>pix) pix=d*y1;
		d=y2; if(d*x1>pix) pix=d*x1;
		d=y1-y2-1; if(d*x1>pix) pix=d*x1;
		printf("%d\n", pix);
	}
	return 0;
}


#include<stdio.h>
int max(int a, int b)
{
	return a > b ? a : b;
}
int main(void)
{
	int t;
	scanf("%d", &t);
	int a, b, x, y;
	int ans1, ans2;
	while (t--)
	{
		ans1 = 0;
		ans2 = 0;
		scanf("%d %d %d %d", &a, &b, &x, &y);
		x += 1;
		y += 1;
		ans1 = (y-1) * a;
		if ((b - y) * a > ans1)
			ans1 = (b - y) * a;
		ans2 = (x - 1) * b;
		if ((a - x) * b > ans2)
			ans2 = (a - x) * b;
		printf("%d\n",max(ans1, ans2));
	}
	return 0;
}


#include <stdio.h>

int main(){
	int t;
	scanf("%d", &t);
	int cima=0, baixo=0, dir=0, esq=0;
		int a, b, x, y;
	for(int i =0; i<t; ++i){
		scanf("%d %d %d %d", &x, &y, &a, &b);
		baixo=(y-1-b)*x;
		cima= b*x;
		//baixo= b*x;
		//cima=(y-1-b)*x;
		dir=(x-1-a)*y;
		esq= a*y ;
/*		printf("%d\n", baixo);
		printf("%d\n", cima);
		printf("%d\n", dir);
		printf("%d\n", esq);
*/
		if ((cima >= baixo) && (cima >= dir) && (cima >= esq))
			printf("%d\n", cima);
		else if ((baixo >= cima) && (baixo >= dir) && (baixo >= esq))
			printf("%d\n", baixo);
		else if ((dir >= cima) && (dir >= baixo) && (dir >= esq))
			printf("%d\n", dir);
		else if ((esq >= baixo) && (esq >= cima) && (esq >= dir))
			printf("%d\n", esq);

	}

	return 0;
}


//Problema 1315A do CodeForces
#include <stdio.h>
#include <stdlib.h>

int main(){
	int t;

	scanf("%d", &t);

	int a, b, x, y;
	int ac = 0, ab = 0, esq = 0, dir = 0;

	for (int i = 0; i < t; ++i){
		scanf("%d %d %d %d", &a, &b, &x, &y);

		ac = x * b;
		ab = (a-x-1) * b;
		esq = a * y;
		dir = a * (b-y-1);

		/*
		acima = x * b
		abaixo = (a-x-1) * b
		à esquerda = a * y
		à direita = a * (b-y-1)
		*/

		if(ac >= ab && ac >= esq && ac >= dir)
			printf("%d\n", ac);

		if(ab >= ac && ab >= esq && ab >= dir)
			printf("%d\n", ab);

		if(esq >= ab && esq >= ab && esq >= dir)
			printf("%d\n", esq);

		if(dir >= ab && dir >= ac && dir >= esq)
			printf("%d\n", dir);
	}
	return 0;
}


//Problema 1315A do CodeForces
#include <stdio.h>
#include <stdlib.h>

int main(){
	int t;

	scanf("%d", &t);

	int a, b, x, y;
	int ac = 0, ab = 0, esq = 0, dir = 0;

	for (int i = 0; i < t; ++i){
		scanf("%d %d %d %d", &a, &b, &x, &y);

		ac = x * b;
		ab = (a-x-1) * b;
		esq = a * y;
		dir = a * (b-y-1);

		/*
		acima = x * b
		abaixo = (a-x-1) * b
		à esquerda = a * y
		à direita = a * (b-y-1)
		*/

		if(ac >= ab && ac >= esq && ac >= dir)
			printf("%d\n", ac);

		else if (ab >= ac && ab >= esq && ab >= dir)
			printf("%d\n", ab);

		else if(esq >= ab && esq >= ab && esq >= dir)
			printf("%d\n", esq);

		else if(dir >= ab && dir >= ac && dir >= esq)
			printf("%d\n", dir);
	}
	return 0;
}


#include<stdio.h>
int main(){
int t,a,b,x,y,i,m,n,k,p;
scanf("%d",&t);
for(i=0;i<t;i++){
scanf("%d",&a);
printf("\t");
scanf("%d",&b);
printf("\t");
scanf("%d",&x);
printf("\t");
scanf("%d",&y);
printf("\n");
}
for(i=0;i<t;i++){
m=(a-x-1)*b;
n=a*y;
k=b*x;
p=a*(b-y-1);
if(m>n){
if(m>k){
if(m>p){printf("%d\n",m);}
else{printf("%d\n",p);}}
else if(k>m&&k>n){printf("%d\n",k);}}
else {printf("%d\n",n);}

}
return 0;}


#include <stdio.h>
int main() {

    int x,y,a,b;
    int n;
    int arr[n];
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a, &b, &x, &y);
        int Smax1, Smax2;

        if(a*x > (a-x-1)*b)
            Smax1 = a*x;
        else Smax1 = (a-x-1)*b;

        if((b-y-1)*a > a*y)
            Smax2 = (b-y-1)*a;
        else Smax2 = a*y;

        if(Smax1 > Smax2) arr[i] = Smax1;
        else arr[i] = Smax2;
        }

     for(int i = 0; i < n; i++)
        printf("%d\n", arr[i]);
}


#include <stdio.h>
int main() {

    int x,y,a,b;
    int n;
    scanf("%d", &n);
    int arr[n];

    for(int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a, &b, &x, &y);
        int Smax1, Smax2;

        if(a*x > (a-x-1)*b)
            Smax1 = a*x;
        else Smax1 = (a-x-1)-b;

        if((b-y-1)*a > a*y)
            Smax2 = (b-y-1)*a;
        else Smax2 = a*y;

        if(Smax1 > Smax2) arr[i] = Smax1;
        else arr[i] = Smax2;
        }

     for(int i = 0; i < n; i++)
        printf("%d\n", arr[i]);
}


#include <stdio.h>
int main() {

    int x,y,a,b;
    int n;
    int arr[n];
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a, &b, &x, &y);
        int Sleft = a*x;
        int Sright = (a-x-1)*b;
        int Stop = (b-y-1)*a;
        int Sbot = a*y;
        int Smax1, Smax2;
        if(Sleft > Sright)
            Smax1 = Sleft;
        else Smax1 = Sright;
        if(Stop > Sbot)
            Smax2 = Stop;
        else Smax2 = Sbot;
        if(Smax1 > Smax2) arr[i] =Smax1;
        else arr[i] = Smax2;
        }

     for(int i = 0; i < n; i++)
        printf("%d\n", arr[i]);
}


#include <stdio.h>
int main() {

    int x,y,a,b;
    int n;

    scanf("%d", &n);
    int arr[n];

    for(int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a, &b, &x, &y);
        int Smax1, Smax2;

        if(x > (a-x-1))
            Smax1 = b*x;
        else Smax1 = (a-x-1)*b;

        if((b-y-1) > y)
            Smax2 = (b-y-1)*a;
        else Smax2 = a*y;

        if(Smax1 > Smax2) arr[i] = Smax1;
        else arr[i] = Smax2;
        }

     for(int i = 0; i < n; i++)
        printf("%d\n", arr[i]);
}


#include <stdio.h>
int main() {

    int x,y,a,b;
    int n;
    int arr[n];
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a, &b, &x, &y);
        int Smax1, Smax2;

        if(a*x > (a-x-1)*b)
            Smax1 = a*x;
        else Smax1 = (a-x-1)-b;

        if((b-y-1)*a > a*y)
            Smax2 = (b-y-1)*a;
        else Smax2 = a*y;

        if(Smax1 > Smax2) arr[i] = Smax1;
        else arr[i] = Smax2;
        }

     for(int i = 0; i < n; i++)
        printf("%d\n", arr[i]);
}


#include <stdio.h>
int main() {

    int x,y,a,b;
    int n;

    scanf("%d", &n);
    int arr[n];

    for(int i = 0; i < n; i++) {
        scanf("%d%d%d%d", &a, &b, &x, &y);
        int Smax1, Smax2;

        if(a*x > (a-x-1)*b)
            Smax1 = a*x;
        else Smax1 = (a-x-1)*b;

        if((b-y-1)*a > a*y)
            Smax2 = (b-y-1)*a;
        else Smax2 = a*y;

        if(Smax1 > Smax2) arr[i] = Smax1;
        else arr[i] = Smax2;
        }

     for(int i = 0; i < n; i++)
        printf("%d\n", arr[i]);
}


    #include <stdio.h>
    int main()
    {
    	int t,x,y,a,b,c,d,ans,ans1;
    	scanf("%d",&t);
    	while(t--){
    		scanf("%d%d%d%d",&a,&b,&x,&y);
    		c=a-x;
    		d=b-y;
    		if(x<c)
    			x=c-1;
    		if(y<d)
    			y=d-1;
    		ans=a*y;
    		ans1=b*x;
    		printf("%d\n",(ans>ans1)?ans:ans1);
    	}
    }


#include<stdio.h>
#include<math.h>
#include<string.h>
int func(int a[],int n){
    int max=0;
    for(int i=0;i<n;i++)
    {
        max=(max>a[i])? max:a[i];
    }
    return max;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b,x,y,c[4];
        scanf("%d%d%d%d",&a,&b,&x,&y);
        if(y-1>=0)
        c[0]=(y)*a;
        else
        c[0]=0;
        if(y+2<b)
        c[1]=(b-y-1)*a;
        else
        c[1]=0;
        if(x-1<=0)
        c[2]=(x)*b;
        else
        c[2]=0;
        if(x+2<a)
        c[3]=(a-x-1)*b;
        else
        c[3]=0;
        printf("%d\n",func(c,4));
    }


#include<stdio.h>
#include<math.h>
#include<string.h>
int func(int a[],int n){
    int max=0;
    for(int i=0;i<n;i++)
    {
        max=(max>a[i])? max:a[i];
    }
    return max;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b,x,y,c[4];
        scanf("%d%d%d%d",&a,&b,&x,&y);
        if(y-1>=0)
        c[0]=(y)*a;
        else
        c[0]=0;
        if(y+2<b)
        c[1]=(b-y-1)*a;
        else
        c[1]=0;
        if(x-1<=0)
        c[2]=(x)*b;
        else
        c[2]=0;
        if(x+2<a)
        c[3]=(a-x-1)*b;
        else
        c[3]=0;
        printf("%d\n",func(c,4));
    }

}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main(){
    int n,m,q;
    string s;
    scanf("%d %d %d\n",&n,&m,&q);
    int w[n];
    forn(i,n) scanf("%d",&w[i]);
    map<string,int>a;
    int k;
    forn(i,m){
        cin>>s;
        a[s]++;
    }
    int c,d,curr,ans;
    forn(i,q){
        cin>>s;
        scanf("%d",&c);
        ans=0;
        for (auto j:a){
            curr=0;
            for (int l=0;l<n;l++)
                if (s[l]==j.first[l]) curr+=w[l];
            if (curr<=c) ans+=j.second;
        }
        printf("%d\n",ans);
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define pb push_back
#define eb emplace_back
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define fi first
#define se second
#define mp make_pair

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef pair<int,int> pii;
typedef long double ld;
typedef complex<ld> p;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    int n, m, q;
    cin >> n >> m >> q;
    int w[12];
    int wu[1 << 12];
    bitset<12> a;
    forn(i, 12 - n) w[i] = 0;
    fore(i, 12 - n, 11) cin >> w[i];
    forn(i, 1 << 12){
        a = i;
        forn(j, 12){
            wu[i] += a[j] * w[11 - j];
        }
        wu[i] = min(wu[i], 101);
    }
    map<unsigned long, int>in;
    forn(i, m){
        cin >> a;
        in[a.to_ulong()]++;
    }
    int f[64][64][102];
    forn(i, 64){
        for(auto j:in){
            f[j.fi >> 6][i][wu[((j.fi % 64) ^ i) ^ 63]] += j.se;
        }
    }
    int g[(1 << 12)][102];
    forn(i, 64){
        forn(j, 64){
            g[(i << 6) + j][0] = f[i][j][0];
            for1(k, 101){
                g[(i << 6) + j][k] = g[(i << 6) + j][k - 1] + f[i][j][k];
            }
        }
    }
    int b;
    forn(i, q){
        cin >> a >> b;
        cout << g[int(a.to_ulong())][b] << "\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define pb push_back
#define eb emplace_back
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); i++)
#define fi first
#define se second
#define mp make_pair

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef pair<int,int> pii;
typedef long double ld;
typedef complex<ld> p;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    int n, m, q;
    cin >> n >> m >> q;
    int w[12];
    int wu[4096];
    bitset<12> a;
    forn(i, 12 - n) w[i] = 0;
    fore(i, 12 - n, 11) cin >> w[i];
    forn(i, 4096){
        a = i;
        forn(j, 12){
            if (a[j] == 0)
                wu[i] += w[11 - j];
        }
    }
    map<unsigned long, int>in;
    forn(i, m){
        cin >> a;
        in[a.to_ulong()]++;
    }
    int f[64][64][101];
    forn(i, 64)
        forn(j, 64)
            forn(k, 101) f[i][j][k] = 0;
    forn(i, 64){
        for(auto j:in){
            if (wu[(j.fi % 64) ^ i] < 101)
                f[j.fi >> 6][i][wu[(j.fi % 64) ^ i]] += j.se;
        }
    }
    int g[4096][101];
    forn(i, 4096)
        forn(j, 101) g[i][j] = 0;
    forn(i, 64){
        forn(j, 64){
            g[(i << 6) + j][0] = f[i][j][0];
            for1(k, 100){
                g[(i << 6) + j][k] = g[(i << 6) + j][k - 1] + f[i][j][k];
            }
        }
    }
    int b;
    forn(i, q){
        cin >> a >> b;
        cout << g[a.to_ulong()][b] << "\n";
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,q;
    string s;
    cin>>n>>m>>q;
    int w[n];
    forn(i,n) cin>>w[i];
    map<string,int>a;
    int k;
    forn(i,m){
        cin>>s;
        a[s]++;
    }
    int c,d,curr,ans;
    forn(i,q){
        cin>>s>>c;
        ans=0;
        for (auto j:a){
            curr=0;
            for (int l=0;l<n;l++)
                if (s[l]==j.first[l]) curr+=w[l];
            if (curr<=c) ans+=j.second;
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,q;
    string s;
    scanf("%d %d %d\n",&n,&m,&q);
    int w[n];
    forn(i,n) scanf("%d",&w[i]);
    map<string,int>a;
    int k;
    forn(i,m){
        cin>>s;
        a[s]++;
    }
    int c,d,curr,ans;
    forn(i,q){
        cin>>s>>c;
        ans=0;
        for (auto j:a){
            curr=0;
            for (int l=0;l<n;l++)
                if (s[l]==j.first[l]) curr+=w[l];
            if (curr<=c) ans+=j.second;
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m,q;
    string s;
    scanf("%d %d %d\n",&n,&m,&q);
    int w[n];
    forn(i,n) scanf("%d",&w[i]);
    map<string,int>a;
    int k;
    forn(i,m){
        cin>>s;
        a[s]++;
    }
    int c,d,curr,ans;
    forn(i,q){
        cin>>s;
        scanf("%d",&c);
        ans=0;
        for (auto j:a){
            curr=0;
            for (int l=0;l<n;l++)
                if (s[l]==j.first[l]) curr+=w[l];
            if (curr<=c) ans+=j.second;
        }
        printf("%d\n",ans);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4100][110][20];
char s[100];
int w[20];
int brute(int k,int num=0,int start=-1){
    if(dp[num^z][k][start+1]!=-1) return dp[num^z][k][start+1];
    string t="";
    ll ans=0;
    for(int i=0;i<n;i++){
        if(num&(1<<i)) { t+=s[i]; continue; }
        if(k-w[i]>=0&i>start) { ans+=brute(k-w[i],num|(1<<i),i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }
    return (dp[num^z][k][start+1]=ans+MS[t]);
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    scanf("%d%d%d",&n,&m,&q);
    ll sum=0;
    for(int i=0;i<n;i++) scanf("%d",w+i), sum+=w[i];
    for(int i=0;i<m;i++) scanf("%s",s), MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        scanf("%s%d",s,&k);
        ll ans=0;
        z=0;
        for(int i=n-1;i>=0;i--){
            if(s[i]=='1') z|=(1<<i);
        }
        if(sum>k)
        ans=brute(k,0);
        else ans=m;
        printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4100][110][20];
char s[100];
int w[20];
ll ans=0;
inline int convert(set<int> st){
    string temp="";
    for(int i=0;i<n;i++){
        if(st.find(i)!=st.end()) temp+=s[i];
        else {
            if(s[i]=='0') temp+='1';
            else temp+='0';
        }
    }
    ll ans=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--){
        if(temp[i]=='1') ans|=(1<<cnt);
        cnt++;
    }
    return ans;
}
ll cnt=0;
int brute(int k,set<int> sameBit,int start=-1){
    ll num=convert(sameBit);
    if(dp[num][k][start+1]!=-1) return dp[num][k][start+1];
    cnt++;
    string t="";
    set<int> sameBit_=sameBit;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(sameBit.find(i)!=sameBit.end()) { t+=s[i]; continue; }
        if(k-w[i]>=0&i>start) { sameBit_.insert(i); ans+=brute(k-w[i],sameBit_,i); sameBit_.erase(i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }

    return (dp[num][k][start+1]=ans+MS[t]);
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    scanf("%d%d%d",&n,&m,&q);
    ll sum=0;
    for(int i=0;i<n;i++) scanf("%d",w+i), sum+=w[i];
    for(int i=0;i<m;i++) scanf("%s",s), MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        scanf("%s%d",s,&k);
        set<int> sameBit;
        if(sum>k)
        ans=brute(k,sameBit);
        else ans=m;
        printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4100][110][20];
string s;
int w[20];
ll ans=0;
inline int convert(set<int> st){
    string temp="";
    for(int i=0;i<n;i++){
        if(st.find(i)!=st.end()) temp+=s[i];
        else {
            if(s[i]=='0') temp+='1';
            else temp+='0';
        }
    }
    ll ans=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--){
        if(temp[i]=='1') ans|=(1<<cnt);
        cnt++;
    }
    return ans;
}
int brute(int k,set<int> sameBit,int start=-1){
    ll num=convert(sameBit);
    if(dp[num][k][start+1]!=-1) return dp[num][k][start+1];
    string t="";
    set<int> sameBit_=sameBit;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(sameBit.find(i)!=sameBit.end()) { t+=s[i]; continue; }
        if(k-w[i]>=0&i>start) { sameBit_.insert(i); ans+=brute(k-w[i],sameBit_,i); sameBit_.erase(i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }

    return (dp[num][k][start+1]=ans+MS[t]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m>>q;
    ll sum=0;
    for(int i=0;i<n;i++) cin>>w[i], sum+=w[i];
    for(int i=0;i<m;i++) cin>>s, MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        cin>>s>>k;
        set<int> sameBit;
        ans=brute(k,sameBit);
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4100][110][20];
char s[100];
int w[20];
int brute(int k,int num=0,int start=-1){
    if(dp[num^z][k][start+1]!=-1) return dp[num][k][start+1];
    string t="";
    ll ans=0;
    for(int i=0;i<n;i++){
        if(num&(1<<i)) { t+=s[i]; continue; }
        if(k-w[i]>=0&i>start) { ans+=brute(k-w[i],num|(1<<i),i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }
    return (dp[num^z][k][start+1]=ans+MS[t]);
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    scanf("%d%d%d",&n,&m,&q);
    ll sum=0;
    for(int i=0;i<n;i++) scanf("%d",w+i), sum+=w[i];
    for(int i=0;i<m;i++) scanf("%s",s), MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        scanf("%s%d",s,&k);
        ll ans=0;
        z=0;
        for(int i=n-1;i>=0;i--){
            if(s[i]=='1') z|=(1<<i);
        }
        if(sum>k)
        ans=brute(k,0);
        else ans=m;
        printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
int freq[4100];
char s[20];
int f[4100][105], w[20];
inline int convert(){
    ll r=0;
    for(int i=n-1;i>=0;i--)
        r|=(1<<(n-1-i))*(s[i]=='1');
    return r;
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    scanf("%d%d%d",&n,&m,&q);
    ll sum=0;
    for(int i=n-1;i>=0;i--) scanf("%d",w+i);
    for(int i=0;i<m;i++) scanf("%s",s), freq[convert()]++;
    for(int i=0;i<(1<<n);i++){
        for(int mask=0;mask<(1<<n);mask++){
            ll sum=0;
            for(int k=0;k<n;k++){
                int set=(mask&(1<<k)), set_=(i&(1<<k));
               // cout<<mask<<' '<<i<<' '<<k<<endl;
                // cout<<mask<<' '<<i<<' '<<set<<' '<<set_<<endl;
                if(!(set^set_)) sum+=w[k];
            }
            if(sum>100) continue;
           // cout<<sum<<' '<<mask<<' '<<i<<endl;
            f[i][sum]+=freq[mask];
        }
    }
    for(int i=0;i<(1<<n);i++)
        for(int j=0;j<=100;j++){
            f[i][j]+=f[i][j-1];
        }
    for(int i=0;i<q;i++){
        scanf("%s%d",s,&k);
        printf("%d\n", f[convert()][min((int)k,100)]);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
string s;
int w[20];
ll ans=0;
void brute(int k,set<int> sameBit,int cur=0, int start=-1){
    string t="";
    set<int> sameBit_=sameBit;
    for(int i=0;i<n;i++){
        if(sameBit.find(i)!=sameBit.end()) { t+=s[i]; continue; }
        if(w[i]+cur<=k&&i>start) { sameBit_.insert(i); brute(k,sameBit_,cur+w[i],i); sameBit_.erase(i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }
    ans+=MS[t];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m>>q;
    for(int i=0;i<n;i++) cin>>w[i];
    for(int i=0;i<m;i++) cin>>s, MS[s]++;
    for(int i=0;i<q;i++){
        cin>>s>>k;
        set<int> sameBit;
        ans=0;
        brute(k,sameBit);
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4100][110];
char s[100];
int w[20];
int brute(int k,int num=0){
    if(dp[num^z][k]!=-1) return dp[num^z][k];
    string t="";
    ll ans=0;
    for(int i=0;i<n;i++){
        if(num&(1<<i)) { t+=s[i]; continue; }
        if(k-w[i]>=0) { ans+=brute(k-w[i],num|(1<<i)); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }
    return (dp[num^z][k]=ans+MS[t]);
}
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0), cout.tie(0);
    scanf("%d%d%d",&n,&m,&q);
    ll sum=0;
    for(int i=0;i<n;i++) scanf("%d",w+i), sum+=w[i];
    for(int i=0;i<m;i++) scanf("%s",s), MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        scanf("%s%d",s,&k);
        ll ans=0;
        z=0;
        for(int i=n-1;i>=0;i--){
            if(s[i]=='1') z|=(1<<i);
        }
        if(sum>k)
        ans=brute(k,0);
        else ans=m;
        printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4100][110][20];
string s;
int w[20];
ll ans=0;
inline int convert(set<int> st){
    string temp="";
    for(int i=0;i<n;i++){
        if(st.find(i)!=st.end()) temp+=s[i];
        else {
            if(s[i]=='0') temp+='1';
            else temp+='0';
        }
    }
    ll ans=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--){
        if(temp[i]=='1') ans|=(1<<cnt);
        cnt++;
    }
    return ans;
}
int brute(int k,set<int> sameBit,int start=-1){
    ll num=convert(sameBit);
    if(dp[num][k][start+1]!=-1) return dp[num][k][start+1];
    string t="";
    set<int> sameBit_=sameBit;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(sameBit.find(i)!=sameBit.end()) { t+=s[i]; continue; }
        if(k-w[i]>=0&i>start) { sameBit_.insert(i); ans+=brute(k-w[i],sameBit_,i); sameBit_.erase(i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }

    return (dp[num][k][start+1]=ans+MS[t]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m>>q;
    ll sum=0;
    for(int i=0;i<n;i++) cin>>w[i], sum+=w[i];
    for(int i=0;i<m;i++) cin>>s, MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        cin>>s>>k;
        set<int> sameBit;
        if(sum>k)
        ans=brute(k,sameBit);
        else ans=m;
        printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef long double D;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1000000000+500;
ll MOD=  1e9+7 ;
const ll mxn= 1e5+10;
const int N=10000005;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
ll n,m,k,y,z,x,q;
map<string,int> MS;
int dp[4050][110];
string s;
int w[20];
ll ans=0;
inline int convert(set<int> st){
    string temp="";
    for(int i=0;i<n;i++){
        if(st.find(i)!=st.end()) temp+=s[i];
        else {
            if(s[i]=='0') temp+='1';
            else temp+='0';
        }
    }
    ll ans=0;
    int cnt=0;
    for(int i=n-1;i>=0;i--){
        if(temp[i]=='1') ans|=(1<<cnt);
        cnt++;
    }
    return ans;
}
int brute(int k,set<int> sameBit){
    ll num=convert(sameBit);
    if(dp[num][k]!=-1) return dp[num][k];
    string t="";
    set<int> sameBit_=sameBit;
    ll ans=0;
    for(int i=0;i<n;i++){
        if(sameBit.find(i)!=sameBit.end()) { t+=s[i]; continue; }
        if(k-w[i]>=0) { sameBit_.insert(i); ans+=brute(k-w[i],sameBit_); sameBit_.erase(i); }
        if(s[i]=='0') t+='1';
        else t+='0';
    }

    return (dp[num][k]=ans+MS[t]);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>m>>q;
    for(int i=0;i<n;i++) cin>>w[i];
    for(int i=0;i<m;i++) cin>>s, MS[s]++;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<q;i++){
        cin>>s>>k;
        set<int> sameBit;
        ans=brute(k,sameBit);
        //cout<<"DP "<<dp[0][100]<<endl;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define xx first
#define yy second
const int B=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e9+10;
ll mod=  998244353;
const ll mxn= 1e6+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
int c[20], f[5100];
int tot[5100][110];
string s;
int to_int(string s){
    int r=0;
    for(int i=0, cnt=s.length()-1;i<s.length();i++,cnt--)
        if(s[i]=='1') r|=(1<<cnt);
    return r;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>n>>q>>m;
    for(int i=0;i<n;i++) cin>>c[n-i-1];
    for(int i=0;i<q;i++){
        cin>>s;
        f[to_int(s)]++;
    }
    for(int mask1=0;mask1<(1<<n);mask1++){
        for(int mask2=0;mask2<(1<<n);mask2++){
            int add=0;
            for(int j=0;j<n;j++){
                int x=mask1&(1<<j), y=mask2&(1<<j);
                if(x==y)  add+=c[j];
            }
            if(add>100) continue;
            //cout<<mask1<<' '<<mask2<<' '<<add<<' '<<f[mask2]<<'\n';
            tot[mask1][add]+=f[mask2];
        }
    }
    for(int mask=0;mask<(1<<n);mask++)
        for(int i=1;i<=100;i++) tot[mask][i]+=tot[mask][i-1];

    while(m--){
        int lim;
        cin>>s>>lim;
        cout<<tot[to_int(s)][lim]<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)
const int MAX=13;
const int MAX1=500001;

int n,m,q;
int w[MAX];
string s[MAX1];

void enter()
{
    cin>>n>>m>>q;
    for1(i,1,n) cin>>w[i];
    for1(i,1,m) cin>>s[i];
}

int test(string t,int k)
{
    int ans,tmp;
    ans=0;
    for1(i,1,m)
    {
        if (i!=1&&s[i]==s[i-1]&&tmp<=k)
        {
            ans++;
            continue;
        }
        tmp=0;
        for1(j,0,n-1)
            if (s[i][j]==t[j]) tmp+=w[j+1];
        if (tmp<=k) ans++;
    }
    return ans;
}

void solve()
{
    string t;
    int k;
    for1(i,1,q)
    {
        cin>>t>>k;
        cout<<test(t,k)<<endl;
    }
}

int main()
{
    enter();
    solve();
}


#include <bits/stdc++.h>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

const int MAX0=13;
const int MAX1=4097;
const int MAX2=101;

int n,m,q,l;
int v[MAX0],a[MAX1],t[MAX1];
int r[MAX1][MAX2];

void enter()
{
    fastio;
    cin>>n>>m>>q;
    for1(i,0,n-1) cin>>v[n-i-1];
}

void prepare1()
{
    int x;
    l=1<<n;
    for1(i,0,l-1)
    {
        x=i;
        for1(j,0,l-1)
        {
            if (x&1) t[i]+=v[j];
            x>>=1;
        }
    }
}

int f(string s)
{
    int x;
    x=0;
    for(char i:s)
    {
        x<<=1;
        if (i=='1') x|=1;
    }
    return x;
}

void prepare2()
{
    string s;
    for1(i,0,m-1)
    {
        cin>>s;
        a[f(s)]++;
    }
}

void prepare3()
{
    int x;
    for1(i,0,l-1)
        for1(j,0,l-1)
        {
            x=t[~(i^j)&(l-1)];
            r[i][x]+=a[j];
        }
}

void prepare4()
{
    for1(i,0,l-1)
        for1(j,0,99) r[i][j+1]+=r[i][j];
}

void solve()
{
    prepare1();
    prepare2();
    prepare3();
    prepare4();
}

void print()
{
    string s;
    int k;
    for1(i,0,q-1)
    {
        cin>>s>>k;
        cout<<r[f(s)][k]<<'\n';
    }
}

int main()
{
    enter();
    solve();
    print();
}


#include <bits/stdc++.h>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

const int MAX0=13;
const int MAX1=4097;
const int MAX2=101;

int n,m,q,l;
int v[MAX0],a[MAX1],t[MAX1];
int r[MAX1][MAX2];

void enter()
{
    fastio;
    cin>>n>>m>>q;
    for1(i,0,n-1) cin>>v[n-i-1];
}

void prepare1()
{
    int x;
    l=1<<n;
    for1(i,0,l-1)
    {
        x=i;
        for1(j,0,l-1)
        {
            if (x&1) t[i]+=v[j];
            x>>=1;
        }
    }
}

int f(string s)
{
    int x;
    x=0;
    for(char i:s)
    {
        x<<=1;
        if (i=='1') x|=1;
    }
    return x;
}

void prepare2()
{
    string s;
    for1(i,0,m-1)
    {
        cin>>s;
        a[f(s)]++;
    }
}

void prepare3()
{
    int x;
    for1(i,0,l-1)
        for1(j,0,l-1)
        {
            x=t[~(i^j)&(l-1)];
            if (x<=100) r[i][x]+=a[j];
        }
}

void prepare4()
{
    for1(i,0,l-1)
        for1(j,0,99) r[i][j+1]+=r[i][j];
}

void solve()
{
    prepare1();
    prepare2();
    prepare3();
    prepare4();
}

void print()
{
    string s;
    int k;
    for1(i,0,q-1)
    {
        cin>>s>>k;
        cout<<r[f(s)][k]<<'\n';
    }
}

int main()
{
    enter();
    solve();
    print();
}


#include <iostream>
#include <string>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)
const int MAX = 13;

string s = "";
int n, m, q;
int w[MAX];

void enter()
{
	string x;
	cin >> n >> m >> q;
	for1(i, 0, n - 1) cin >> w[i];
	for1(i, 1, m)
	{
		cin >> x;
		s = s + x;
	}
}

int checkValue(string t, int k)
{
	int *mid=new int[m+1];
	int ans, tmp;
	string temp1 = t;
	for1(i, 1, m - 1) t += temp1;
	for1(i, 0, m*n-1)
		if (s[i] == t[i]) mid[i] = 1;
		else mid[i] = 0;
	tmp = 0;
	ans = 0;
	for1(i, 0, m*n - 1)
	{
		tmp += mid[i] * w[i%n];
		if (i%n == n - 1)
		{
			if (tmp <= k) ans++;
			tmp = 0;
		}
	}
	delete[] mid;
	return ans;
}

void solve()
{
	string t;
	int k;
	for1(i, 1, q)
	{
		cin >> t >> k;
		cout << checkValue(t, k) << endl;
	}
}

int main()
{
	enter();
	solve();
}


#include <bits/stdc++.h>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);

const int MAX0=13;
const int MAX1=1<<13;
const int MAX2=101;

int n,m,q,l;
int v[MAX0],a[MAX1],t[MAX1];
int r[MAX1][MAX2];

void enter()
{
    fastio
    cin>>n>>m>>q;
    for1(i,0,n-1) cin>>v[n-i-1];
}

void prepare1()
{
    int x;
    l=1<<n;
    for1(i,0,l-1)
    {
        x=i;
        for1(j,0,l-1)
        {
            if (x&1) t[i]+=v[j];
            x>>=1;
        }
    }
}

int f(string s)
{
    int x;
    x=0;
    for(char i:s)
    {
        x<<=1;
        if (i=='1') x|=1;
    }
    return x;
}

void prepare2()
{
    string s;
    for1(i,0,m-1)
    {
        cin>>s;
        a[f(s)]++;
    }
}

void prepare3()
{
    int x;
    for1(i,0,l-1)
        for1(j,0,l-1)
        {
            x=t[~(i^j)&(l-1)];
            if (x<=100) r[i][x]+=a[j];
        }
}

void prepare4()
{
    for1(i,0,l-1)
        for1(j,0,99) r[i][j+1]+=r[i][j];
}

void solve()
{
    prepare1();
    prepare2();
    prepare3();
    prepare4();
}

void print()
{
    string s;
    int k;
    for1(i,0,q-1)
    {
        cin>>s>>k;
        cout<<r[f(s)][k]<<'\n';
    }
}

int main()
{
    enter();
    solve();
    print();
}


#include <bits/stdc++.h>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)

const int MAX0=13;
const int MAX1=4097;
const int MAX2=101;

int n,m,q,l;
int v[MAX0],t[MAX1],a[MAX1];
int r[MAX1][MAX2];

void enter()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>q;
    for1(i,0,n-1) cin>>v[n-i-1];
}

void prepare1()
{
    int x;
    l=1<<n;
    for1(i,0,l-1)
    {
        x=i;
        for1(j,0,l-1)
        {
            if (x&1) t[i]+=v[j];
            x>>=1;
        }
    }
}

int f(string s)
{
    int x;
    x=0;
    for(char i:s)
    {
        x<<=1;
        if (i=='1') x|=1;
    }
    return x;
}

void prepare2()
{
    string s;
    for1(i,0,m-1)
    {
        cin>>s;
        a[f(s)]++;
    }
}

void prepare3()
{
    int x;
    for1(i,0,l-1)
        for1(j,0,l-1)
        {
            x=t[~(i^j)&(l-1)];
            if (x<=100) r[i][x]+=a[j];
        }
}

void prepare4()
{
    for1(i,0,l-1)
        for1(j,0,99) r[i][j+1]+=r[i][j];
}

void solve()
{
    prepare1();
    prepare2();
    prepare3();
    prepare4();
}

void print()
{
    string s;
    int k;
    for1(i,0,q-1)
    {
        cin>>s>>k;
        cout<<r[f(s)][k]<<'\n';
    }
}

int main()
{
    enter();
    solve();
    print();
}


#include <bits/stdc++.h>
using namespace std;
#define for1(i,a,b) for(int i=a;i<=b;i++)

const int MAX0=13;
const int MAX1=4097;
const int MAX2=101;

int n,m,q,l;
int v[MAX0],t[MAX1],a[MAX1];
int r[MAX1][MAX2];

void enter()
{
    cin>>n>>m>>q;
    for1(i,0,n-1) cin>>v[n-i-1];
}

void prepare1()
{
    int x;
    l=1<<n;
    for1(i,0,l-1)
    {
        x=i;
        for1(j,0,l-1)
        {
            if (x&1) t[i]+=v[j];
            x>>=1;
        }
    }
}

int f(string s)
{
    int x;
    x=0;
    for(char i:s)
    {
        x<<=1;
        if (i=='1') x|=1;
    }
    return x;
}

void prepare2()
{
    string s;
    for1(i,0,m-1)
    {
        cin>>s;
        a[f(s)]++;
    }
}

void prepare3()
{
    int x;
    for1(i,0,l-1)
        for1(j,0,l-1)
        {
            x=t[~(i^j)&(l-1)];
            if (x<=100) r[i][x]+=a[j];
        }
}

void prepare4()
{
    for1(i,0,l-1)
        for1(j,0,99) r[i][j+1]+=r[i][j];
}

void solve()
{
    prepare1();
    prepare2();
    prepare3();
    prepare4();
}

void print()
{
    string s;
    int k;
    for1(i,0,q-1)
    {
        cin>>s>>k;
        cout<<r[f(s)][k]<<'\n';
    }
}

int main()
{
    enter();
    solve();
    print();
}


#include <bits/stdc++.h>
using namespace std;

#define fastio         ios_base::sync_with_stdio(0); cin.tie(0);
#define forb(i,s,n,b)  for(int i = int(s); b && i < int(n); i++)
#define ford(i,s,n)    for(int i = int(n-1) ; i >= int(s) ; i--)
#define fors(i,s,n)    for(int i = int(s) ; i < int(n) ; i++)
#define forn(i,n)      for(int i = 0 ; i < int(n) ; i++)
#define D(a)           cerr << #a << " = " << a << endl;
#define all(a)         a.begin(),a.end()
#define sz(a)          int((a).size())
#define pb             emplace_back
#define mp             make_pair
#define ss             second
#define ff             first
#define endl           '\n'
typedef pair<int,int>  pii;
typedef long long int  ll;
typedef vector<int>    vi;

const int N = 1 << 12;
ll a[N], r[N][101], t[N];

int f(string s){
	int x = 0;
	for(char i : s){
		x <<= 1;
		if(i == '1') x |= 1;
	}
	return x;
}

int main() {

	int n,m,q; cin >> n >> m >> q;
	int l = 1 << n, v[n];
	forn(i,n) cin >> v[n-i-1];
	forn(i,l){
		int x = i;
		forn(j,n){
			if(x & 1) t[i] += v[j];
			x >>= 1;
		}
	}
	forn(i,m){
		string s; cin >> s;
		a[f(s)]++;
	}
	forn(i,l) forn(j,l){
		int x = t[ ~(i^j) & (l-1) ];
		if(x <= 100) r[i][x] += a[j];
	}
	forn(i,l) forn(j,100) r[i][j+1] += r[i][j];
	while(q--){
		string s; cin >> s;
		int k; cin >> k;
		cout << r[f(s)][k] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }

    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW, 0);
        for (auto s: S)
            test_wu_table[i][wu_table[i][s.first]] += s.second;
        //sort(test_wu_table[i].begin(), test_wu_table[i].end());
        for (size_t j = 1; j < MAXW; j++)
            test_wu_table[i][j] += test_wu_table[i][j - 1];
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][k] << endl;
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k, MAXW = 1;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++){
        cin >> w[i];
        MAXW += w[i];
    }
    MAXW = min(101, MAXW);
    unordered_map<int, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(bitset<12>(s).to_ulong())) S[bitset<12>(s).to_ulong()]++;
        else S[bitset<12>(s).to_ulong()] = 1;
    }

    vector<int> wu_table(1 << n, 0);

    for (int i = 0; i < (1 << n); i++)
        for (int j = 0; j < n; j++)
            wu_table[i] += w[n - 1 - j] * (1 - ((i >> j) & 1));

    vector<vector<int>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        test_wu_table[i] = vector<int>(MAXW, 0);
        for (auto s: S) {
            if (wu_table[i ^ s.first] < MAXW) {
                test_wu_table[i][wu_table[i ^ s.first]] += s.second;
            }
        }

        for (int j = 1; j <= MAXW - 1; j++){
            test_wu_table[i][j] += test_wu_table[i][j - 1];
        }
    }

    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        cout << test_wu_table[t_v][min(k, MAXW - 1)] << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int wu(int u, int v, vector<int>* w) {
    int answer = 0;
    for (size_t i = 0; i < (*w).size(); i++)
        if ((u >> i & 1) == (v >> i & 1)) answer += w->at((*w).size() - 1 - i);

    return answer;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q, k;
    string s, t;

    cin >> n >> m >> q;
    vector<int> w(n);
    for (int i = 0; i < n; i++) cin >> w[i];

    unordered_map<string, int> S;

    for (int i = 0; i < m; i++) {
        cin >> s;
        if (S.count(s)) S[s]++;
        else S[s] = 1;
    }

    vector<vector<int>> wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++)
        wu_table[i] = vector<int>(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (int j = i; j < (1 << n); j++) {
            wu_table[i][j] = wu(i, j, &w);
            wu_table[j][i] = wu_table[i][j];
        }
    }

    vector<vector<pair<int, int>>> test_wu_table(1 << n);

    for (int i = 0; i < (1 << n); i++) {
        for (auto s: S) {
            test_wu_table[i].push_back(make_pair(wu_table[i][bitset<12>(s.first).to_ulong()], s.second));
        }
        sort(test_wu_table[i].begin(), test_wu_table[i].end());
        for (size_t j = 1; j < test_wu_table[i].size(); j++)
            test_wu_table[i][j].second += test_wu_table[i][j - 1].second;
    }
    for (int i = 0; i < q; i++) {
        cin >> t >> k;
        int t_v = bitset<12>(t).to_ulong();
        auto index = upper_bound(test_wu_table[t_v].begin(), test_wu_table[t_v].end(), make_pair(k, m + 1));
        index--;
        cout << (*index).second << endl;
    }
}