#include <iostream>
#include <cstdio>

int main()
{
    int n,k;
    FILE* inf = fopen("pijaca.in","r");
    FILE* outf = fopen("pijaca.out", "w");
    fscanf(inf, "%d", &n);
    for(int i=0;i<n;i++) fscanf(inf, "%d", &k);
    fscanf(inf, "%d", &k);
    int br=0;
    for(int i=0;i<k;i++)
    {
            int t;
            fscanf(inf, "%d", &t);
            if(t==1)
            {
                    fscanf(inf, "%d", &t);
                    fscanf(inf, "%d", &t);
                    fscanf(inf, "%d", &t);
                    fscanf(inf, "%d", &t);
                    if(br==0)fprintf(outf, "2\n");
                    else if(br==1)fprintf(outf, "3\n");
                    else fprintf(outf, "16\n");
                    br++;
            }
            else
            {
                fscanf(inf, "%d", &t);
                fscanf(inf, "%d", &t);
            }
    }
    fclose(inf);
    fclose(outf);
    return 0;
}
