#include #include #include using namespace std; const int MAXM = (1 << 16); const int MAXN = 100000 + 10; int a[4][4], bit[4][4]; int reach[MAXM], f[MAXM], num[MAXN], n, m, pI[16], pJ[16]; struct Node { int l, r, xsum; } tree[MAXN * 4]; int aToInt () { int ret = 0; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) { ret += a[i][j] * (1 << bit[i][j]); } return ret; } void prepare () { int seqBits = 0; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) { bit[i][j] = seqBits++; pI[seqBits - 1] = i; pJ[seqBits - 1] = j; } for(int i = 1; i < (1 << seqBits); i++) { for(int j = 0; j < seqBits; j++) if ((i & (1 << j)) > 0) { a[pI[j]][pJ[j]] = 1; } else { a[pI[j]][pJ[j]] = 0; } for(int x1 = 0; x1 < 4; x1++) for(int y1 = 0; y1 < 4; y1++) { for(int x2 = x1; x2 < 4; x2++) for(int y2 = y1; y2 < 4; y2++) { bool fail = false; for(int i = x1; i <= x2; i++) for(int j = y1; j <= y2; j++) if (a[i][j] == 0) fail = true; if (fail) continue; for(int i = x1; i <= x2; i++) for(int j = y1; j <= y2; j++) a[i][j] = 0; int gf = aToInt(); for(int i = x1; i <= x2; i++) for(int j = y1; j <= y2; j++) a[i][j] = 1; reach[f[gf]] = i; } } f[i] = 0; while (reach[f[i]] == i) ++f[i]; } } void init (int pos, int l, int r) { tree[pos].l = l; tree[pos].r = r; if (l < r) { init(pos + pos, l, (l + r) / 2); init(pos + pos + 1, (l + r) / 2 + 1, r); tree[pos].xsum = tree[pos + pos].xsum ^ tree[pos + pos + 1].xsum; } else tree[pos].xsum = num[l]; } int query (int pos, int l, int r) { if (tree[pos].l == l && tree[pos].r == r) return tree[pos].xsum; else { int ret = 0; if (l <= min(r, tree[pos + pos].r)) ret ^= query(pos + pos, l, min(r, tree[pos + pos].r)); if (max(l, tree[pos + pos + 1].l) <= r) ret ^= query(pos + pos + 1, max(l, tree[pos + pos + 1].l), r); return ret; } } void modify (int pos, int j, int x) { if (tree[pos].l == tree[pos].r) { tree[pos].xsum = x; } else { if (tree[pos + pos].r >= j) modify(pos + pos, j, x); else modify(pos + pos + 1, j, x); tree[pos].xsum = tree[pos + pos].xsum ^ tree[pos + pos + 1].xsum; } } void readA () { char trash[10]; for(int x = 0; x < 4; x++){ for(int y = 0; y < 4; y++) { char ch = getchar(); while (ch != '0' && ch != '1') ch = getchar(); a[x][y] = ch - '0'; } } } int main(int argc, const char * argv[]) { prepare(); int tn; scanf("%d", &tn); while (tn--) { scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) { readA(); num[i] = f[aToInt()]; } init(1, 1, n); for(int i = 1; i <= m; i++) { int op; scanf("%d", &op); if (op == 1) { int l, r; scanf("%d %d", &l, &r); int qr = query(1, l, r); if (qr != 0) { puts("Pishty"); } else { puts("Lotsy"); } } else { int p; scanf("%d", &p); readA(); modify(1, p, f[aToInt()]); } } } return 0; }