const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        l++
        const [n, m] = lines[l++].trim().split(' ').map(Number)
        const arr = lines.slice(l, l + n).map(str => str.trim())
        l += n
        const str = lines[l++]
        output[i] = solve(n, m, arr, str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, arr, str) {
    const map = {}
    arr.forEach((s, j) => {
        for (let i = 0; i < s.length; i++) {
            if (i + 1 < s.length) {
                const x = s.slice(i, i + 1 + 1)
                map[x] = [i + 1, i + 2, j + 1]
            }
            if (i + 2 < s.length) {
                const x = s.slice(i, i + 2 + 1)
                map[x] = [i + 1, i + 3, j + 1]
            }
        }
    })
    const dp = []
    dp[0] = []
    dp[1] = null
    for (let i = 2; i <= str.length; i++) {
        const a1 = dp[i - 2]
        const a2 = map[str.slice(i - 2, i)]
        if (a1 && a2) {
            dp[i] = 2
            continue
        }
        const b1 = i - 3 >= 0 ? dp[i - 3] : null
        const b2 = map[str.slice(i - 3, i)]
        if (b1 && b2) {
            dp[i] = 3
            continue
        }
        dp[i] = null
    }
    // console.log(dp)
    if (!dp[m]) return -1
    let x = m
    const ans = []
    dp[0] = null // tricky
    while (dp[x]) {
        // console.log(x)
        ans.unshift(map[str.slice(x - dp[x], x)])
        x -= dp[x]
    }
    return ans.length + '\n' + ans.map(r => r.join(' ')).join('\n')
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = false;
        if(!c1 )
            c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 <= ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 <= ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1);
        mashaForgetul(0);
        if(arr[0]=== true){
            solution = solution.reverse();
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(...solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		const known = [];
		for (let i = 0; i < n; i++) {
			known[i] = rl();
		}
		const s = rl();

		const avl = new Map();
		for (let i = 0; i < n; i++) {
			const ph = known[i];
			for (let j = 0; j < m; j++) {
				j+2 <= m && avl.set(ph.substr(j, 2), [j+1, j+2, i+1]);
				j+3 <= m && avl.set(ph.substr(j, 3), [j+1, j+3, i+1]);
			}
		}

		const dp = Array(n);
		dp[-1] = dp[-2] = true;
		for (let i = 1; i < m; i++) {
			const sx2 = s.substr(i-1, 2);
			const sx3 = s.substr(i-2, 3);

			if (dp[i-2] && avl.has(sx2)) {
				dp[i] = 2;
			} else if (dp[i-3] && avl.has(sx3)) {
				dp[i] = 3;
			}
		}

		if (dp[m-1]) {
			const ans = [];
			let i = m - 1;
			while (i >= 0) {
				const sx = s.substr(i-dp[i]+1, dp[i]);
				ans.push(avl.get(sx));
				i -= dp[i];
			}
			ans.reverse();

			console.log(ans.length);
			for (const ln of ans) {
				console.log(ln.join(' '));
			}
		} else {
			console.log(-1);
		}
	}
}

/*
===== READ INPUT DATA START =====
=================================
*/

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let N, M;
  let arr, str;

  while (T--) {
    [N, M] = lines[index++].split(' ').map(Number);
    arr = new Array(N);

    for (let i = 0; i < N; ++i) {
      arr[i] = lines[index++];
    }

    str = lines[index++];

    solve(N, M, arr, str);
  }
}

function solve(N, M, arr, str) {
  const map = new Map();
  const darr = new Array(M + 1).fill('');
  const solution = [];
  let index;
  let curStr;
  let strLength2;
  let strLength3;

  // base set with sequences of length 2 and 3
  for (let i = 0; i < N; ++i) {
    for (let j = 0; j < M; ++j) {
      strLength2 = arr[i][j] + arr[i][j + 1];
      strLength3 = strLength2 + arr[i][j + 2];

      if (strLength2.length === 2) {
        map.set(strLength2, [j + 1, j + 2, i + 1]);
      }

      if (strLength3.length === 3) {
        map.set(strLength3, [j + 1, j + 3, i + 1]);
      }
    }
  }

  curStr = '';

  for (let i = 1; i <= M; ++i) {
    curStr += str[i - 1];
    strLength2 = str[i - 2] + str[i - 1];
    strLength3 = str[i - 3] + strLength2;

    strLength2 = (map.has(strLength2) && strLength2) || '';
    strLength3 = (map.has(strLength3) && strLength3) || '';

    if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {
      darr[i] = curStr;
    }
  }

  if (!darr[M]) {
    console.log('-1');
    return;
  }

  index = M;

  while (index > 0) {
    strLength2 = str[index - 2] + str[index - 1];
    strLength3 = str[index - 3] + strLength2;

    if ((darr[index - 3] || darr[index] === strLength3) && map.has(strLength3)) {
      solution.push(map.get(strLength3));
      index -= 3;
    } else {
      solution.push(map.get(strLength2));
      index -= 2;
    }
  }

  solution.reverse();

  console.log(solution.length);
  for (let i = 0; i < solution.length; ++i) {
    console.log(solution[i].join(' '));
  }
}

/*
===== READ INPUT DATA START =====
=================================
*/

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let N, M;
  let arr, str;

  while (T--) {
    [N, M] = lines[index++].split(' ').map(Number);
    arr = new Array(N);

    for (let i = 0; i < N; ++i) {
      arr[i] = lines[index++];
    }

    str = lines[index++];

    solve(N, M, arr, str);
  }
}

function solve(N, M, arr, str) {
  const map = new Array(1000);
  const darr = new Array(M + 1).fill('');
  const solution = [];
  let index;
  let curStr;
  let strLength2;
  let strLength3;

  // base set with sequences of length 2 and 3
  for (let i = 0; i < N; ++i) {
    for (let j = 0; j < M; ++j) {
      strLength2 = arr[i][j] + arr[i][j + 1];
      strLength3 = strLength2 + arr[i][j + 2];

      if (strLength2.length === 2) {
        map[Number(strLength2)] = [j + 1, j + 2, i + 1];
      }

      if (strLength3.length === 3) {
        map[Number(strLength3)] = [j + 1, j + 3, i + 1];
      }
    }
  }

  curStr = '';

  for (let i = 1; i <= M; ++i) {
    curStr += str[i - 1];
    strLength2 = str[i - 2] + str[i - 1];
    strLength3 = str[i - 3] + strLength2;

    strLength2 = (map[Number(strLength2)] && strLength2) || '';
    strLength3 = (map[Number(strLength3)] && strLength3) || '';

    if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {
      darr[i] = curStr;
    }
  }

  if (!darr[M]) {
    console.log('-1');
    return;
  }

  index = M;

  while (index > 0) {
    strLength2 = str[index - 2] + str[index - 1];
    strLength3 = str[index - 3] + strLength2;

    if ((darr[index - 3] || darr[index] === strLength3) && map[Number(strLength3)]) {
      solution.push(map[Number(strLength3)]);
      index -= 3;
    } else {
      solution.push(map[Number(strLength2)]);
      index -= 2;
    }
  }

  solution.reverse();

  console.log(solution.length);

  for (let i = 0; i < solution.length; ++i) {
    console.log(solution[i].join(' '));
  }
}

/*
===== READ INPUT DATA START =====
=================================
*/

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';

process.stdin.on('data', (inputStdin) => {
  inputString += inputStdin;
});

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let N, M;
  let arr, str;

  while (T--) {
    [N, M] = lines[index++].split(' ').map(Number);
    arr = new Array(N);

    for (let i = 0; i < N; ++i) {
      arr[i] = lines[index++];
    }

    str = lines[index++];

    solve(N, M, arr, str);
  }
}

function solve(N, M, arr, str) {
  const map = new Array(1000);
  const darr = new Array(M + 1).fill('');
  const solution = [];
  let index;
  let curStr;
  let strLength2;
  let strLength3;

  // base set with sequences of length 2 and 3
  for (let i = 0; i < N; ++i) {
    for (let j = 0; j < M; ++j) {
      strLength2 = arr[i][j] + arr[i][j + 1];
      strLength3 = strLength2 + arr[i][j + 2];

      if (strLength2.length === 2) {
        map[Number(strLength2)] = [j + 1, j + 2, i + 1];
      }

      if (strLength3.length === 3) {
        map[Number(strLength3)] = [j + 1, j + 2, i + 1];
      }
    }
  }

  curStr = '';

  for (let i = 1; i <= M; ++i) {
    curStr += str[i - 1];
    strLength2 = str[i - 2] + str[i - 1];
    strLength3 = str[i - 3] + strLength2;

    strLength2 = (map[Number(strLength2)] && strLength2) || '';
    strLength3 = (map[Number(strLength3)] && strLength3) || '';

    if (darr[i - 2] + strLength2 === curStr || darr[i - 3] + strLength3 === curStr) {
      darr[i] = curStr;
    }
  }

  if (!darr[M]) {
    console.log('-1');
    return;
  }

  index = M;

  while (index > 0) {
    strLength2 = str[index - 2] + str[index - 1];
    strLength3 = str[index - 3] + strLength2;

    if ((darr[index - 3] || darr[index] === strLength3) && map[Number(strLength3)]) {
      solution.push(map[Number(strLength3)]);
      index -= 3;
    } else {
      solution.push(map[Number(strLength2)]);
      index -= 2;
    }
  }

  solution.reverse();

  console.log(solution.length);

  for (let i = 0; i < solution.length; ++i) {
    console.log(solution[i].join(' '));
  }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 <= ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 <= ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]=== true){
            solution = solution.reverse();
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(...solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 < ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 < ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]=== true){
            solution = solution.reverse();
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(...solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 < ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 < ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]){
            solution = solution.reverse();
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(...solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 < ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 < ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]){
            solution = solution.reverse().sort((a,b)=> a[2] - b[2]);
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(...solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 < ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 < ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]){
            solution = solution.reverse().sort((a,b)=> a[2] - b[2]);
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 < ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 < ns.length && map.set(ns.substring(k, k+3), [k+1, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]){
            solution = solution.reverse();
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

let map = null;
let s = null;
let arr = null;
let solution = []
function main() {
    const mashaForgetul = (i)=>{
        if(i >= s.length){
            return true;
        }
        if(arr[i]!= -1) return arr[i];
        let s1 = s.substring(i, i+2);
        let s2 = s.substring(i, i+3);

        let c1 = map.has(s1) && mashaForgetul(i+2);
        let c2 = map.has(s2) && mashaForgetul(i+3);

        if(c2 ){
            let val = map.get(s2);
            solution.push([...val])
        }
        else{
            if(c1){
                let val = map.get(s1);
                solution.push([...val])
            }
        }
        arr[i] = c1||c2;

        return c1 || c2;
    }
    //take input according to the format;
    const t = +(readline());
    readline();
    for(let i =0; i<t; ++i){
        map = new Map()
        solution = [];
        const n = readline().split(' ')[0];

        for(let j =0; j< n; ++j){
            const ns = readline();

            for(let k=0; k<ns.length; ++k){
                k+2 < ns.length && map.set(ns.substring(k, k+2), [k+1, k+2, j+1] );
                k+3 < ns.length && map.set(ns.substring(k, k+3), [k+2, k+3, j+1] );
            }
        }
        s = readline();

        arr = new Array(s.length).fill(-1)
        mashaForgetul(0);
        if(arr[0]){
            solution = solution.reverse();
            console.log(solution.length)
            for(let j = 0; j< solution.length; ++j){
                console.log(solution[j]);
            }
        }
        else{
            console.log(-1)
        }
        readline();

    }
}


const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
const matrix = [];
let n, m;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  matrix.push(d.split(''));

  c++;
});

rl.on('close', () => {
  let width = 1;
  let height = 1;
  let x, y;

  for (let i = 0; i < matrix.length; i++) {
    for (let j = 0; j < matrix[i].length; j++) {
      if (matrix[i][j] === 'B') {
        x = j;
        y = i;

        while (matrix[i] && matrix[i][j] === 'B') {
          if (matrix[i][j + 1] === 'B') {
            width++;
            j++;
          }
          else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {
            height++;
            i++;
          }
          else {
            j++;
            i++;
          }
        }

        break;
      }
    }
  }

  console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));
});

var opt = readline().split(' ');
var row = parseInt(opt[0]);
var column = parseInt(opt[1]);
var squareMassive=[];
squareMassive.length = row;

function findCentre(row,column)
{
    for(var i=0;i<row;i++)
    {
        squareMassive[i] = readline();
        var sStart = null;
        var squareLength=0;
        for(var j=0;j<column;j++)
        {
            if (squareMassive[i][j]=='B') {
                var t = j;
                while(squareMassive[i][++t] === 'B');
                var c = (t - j+1) / 2;
                return {
                    row: i + c,
                    column: j + c
                };
            }
        }

    }

}

var result=findCentre(row,column);
print(result.row);
print(result.column)

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];

print(output(k, n))

function output(k, n) {
    var arr = []
    for (var i = 0; i < n; i++) {
        var string = readline();
        arr.push(string);
    }
    var edjeX1 = 0;
    var edjeX2 = parseInt(k) - 1;
    var edjeY1 = 0;
    var edjeY2 = parseInt(n) - 1;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < k; j++) {
            if (arr[i][j] === "B" && edjeX1 === 0) {
                edjeX1 = j + 1;
            }
            if (arr[i][j] === "W" && j > 0 && arr[i][j-1] === "B" && edjeX2 === parseInt(k) - 1) {
                edjeX2 = j;
            }
            if (arr[i][j] === "B" && edjeY1 === 0) {
                edjeY1 = i + 1;
            }
            if (arr[i][j] === "W" && i > 0 && arr[i-1][j] === "B" && edjeY2 === parseInt(n) - 1) {
                edjeY2 = i;
            }
        }
    }
    return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
	}
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			if(list[i][j] == "B"){
				var add = -1;
				for(var k = 0; k < Math.min(H, W); k++){
					try{
						if(list[i + k][j + k] == "B"){
							add++;
						}else{
							break;
						}
					}catch(e){
						break;
					}

				}
				add = Math.ceil(add / 2);
				myout((i + 1 + add) + " " + (j + 1 + add));
				return;
			}
		}
	}
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
const matrix = [];
let n, m;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  matrix.push(d.split(''));

  c++;
});

rl.on('close', () => {
  const idxTop = [];
  const idxBottom = [];

  isDone:
  for (let i = 0; i < matrix.length; i++) {
    for (let j = 0; j < matrix[i].length; j++) {
      if (matrix[i][j] === 'B') {
        idxTop.push(i + 1, j + 1);
        break isDone;
      }
    }
  }

  isDone:
  for (let i = matrix.length - 1; i >= 0; i--) {
    for (let j = matrix[i].length - 1; j >= 0; j--) {
      if (matrix[i][j] === 'B') {
        idxBottom.push(i + 1, j + 1);
        break isDone;
      }
    }
  }

  const y = (idxTop[0] + idxBottom[0]) / 2;
  const x = (idxTop[1] + idxBottom[1]) / 2;

  console.log(y, x);

  // let width = 1;
  // let height = 1;
  // let x, y;

  // for (let i = 0; i < matrix.length; i++) {
  //   for (let j = 0; j < matrix[i].length; j++) {
  //     if (matrix[i][j] === 'B') {
  //       x = j;
  //       y = i;

  //       while (matrix[i] && matrix[i][j] === 'B') {
  //         if (matrix[i][j + 1] === 'B') {
  //           width++;
  //           j++;
  //         }
  //         else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {
  //           height++;
  //           i++;
  //         }
  //         else {
  //           j++;
  //           i++;
  //         }
  //       }

  //       break;
  //     }
  //   }
  // }

  // console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));
});

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
const matrix = [];
let n, m;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  matrix.push(d.split(''));

  c++;
});

rl.on('close', () => {
  let x = 0;
  let y = 0;
  let cnt = 0;

  for (let i = 0; i < matrix.length; i++) {
    for (let j = 0; j < matrix[i].length; j++) {
      if (matrix[i][j] === 'B') {
        x += j;
        y += i;
        cnt++;
      }
    }
  }

  console.log(y / cnt + 1, x / cnt + 1);

  // let minX = Infinity;
  // let maxX = -Infinity;
  // let minY = Infinity;
  // let maxY = -Infinity;

  // for (let i = 0; i < matrix.length; i++) {
  //   for (let j = 0; j < matrix[i].length; j++) {
  //     if (matrix[i][j] === 'B') {
  //       minX = Math.min(minX, j);
  //       maxX = Math.max(maxX, j);
  //       minY = Math.min(minY, i);
  //       maxY = Math.max(maxY, i);
  //     }
  //   }
  // }

  // console.log((minY + maxY) / 2 + 1, (minX + maxX) / 2 + 1);
  ////////////////////////////////////////////

  // const idxTop = [];
  // const idxBottom = [];

  // isDone: {
  //   for (let i = 0; i < matrix.length; i++) {
  //     for (let j = 0; j < matrix[i].length; j++) {
  //       if (matrix[i][j] === 'B') {
  //         idxTop.push(i + 1, j + 1);
  //         break isDone;
  //       }
  //     }
  //   }
  // }

  // isDone: {
  //   for (let i = matrix.length - 1; i >= 0; i--) {
  //     for (let j = matrix[i].length - 1; j >= 0; j--) {
  //       if (matrix[i][j] === 'B') {
  //         idxBottom.push(i + 1, j + 1);
  //         break isDone;
  //       }
  //     }
  //   }
  // }

  // const y = (idxTop[0] + idxBottom[0]) / 2;
  // const x = (idxTop[1] + idxBottom[1]) / 2;

  // console.log(y, x);
  //////////////////////////////////////

  // let width = 1;
  // let height = 1;
  // let x, y;

  // for (let i = 0; i < matrix.length; i++) {
  //   for (let j = 0; j < matrix[i].length; j++) {
  //     if (matrix[i][j] === 'B') {
  //       x = j;
  //       y = i;

  //       while (matrix[i] && matrix[i][j] === 'B') {
  //         if (matrix[i][j + 1] === 'B') {
  //           width++;
  //           j++;
  //         }
  //         else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {
  //           height++;
  //           i++;
  //         }
  //         else {
  //           j++;
  //           i++;
  //         }
  //       }

  //       break;
  //     }
  //   }
  // }

  // console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));
});

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
const matrix = [];
let n, m;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, m] = d.split(' ').map(Number);
    return;
  }

  matrix.push(d.split(''));

  c++;
});

rl.on('close', () => {
  let minX = Infinity;
  let maxX = -Infinity;
  let minY = Infinity;
  let maxY = -Infinity;

  for (let i = 0; i < matrix.length; i++) {
    for (let j = 0; j < matrix[i].length; j++) {
      if (matrix[i][j] === 'B') {
        minX = Math.min(minX, j);
        maxX = Math.max(maxX, j);
        minY = Math.min(minY, i);
        maxY = Math.max(maxY, i);
      }
    }
  }

  console.log((minY + maxY) / 2 + 1, (minX + maxX) / 2 + 1);

  // const idxTop = [];
  // const idxBottom = [];

  // isDone: {
  //   for (let i = 0; i < matrix.length; i++) {
  //     for (let j = 0; j < matrix[i].length; j++) {
  //       if (matrix[i][j] === 'B') {
  //         idxTop.push(i + 1, j + 1);
  //         break isDone;
  //       }
  //     }
  //   }
  // }

  // isDone: {
  //   for (let i = matrix.length - 1; i >= 0; i--) {
  //     for (let j = matrix[i].length - 1; j >= 0; j--) {
  //       if (matrix[i][j] === 'B') {
  //         idxBottom.push(i + 1, j + 1);
  //         break isDone;
  //       }
  //     }
  //   }
  // }

  // const y = (idxTop[0] + idxBottom[0]) / 2;
  // const x = (idxTop[1] + idxBottom[1]) / 2;

  // console.log(y, x);
  //////////////////////////////////////

  // let width = 1;
  // let height = 1;
  // let x, y;

  // for (let i = 0; i < matrix.length; i++) {
  //   for (let j = 0; j < matrix[i].length; j++) {
  //     if (matrix[i][j] === 'B') {
  //       x = j;
  //       y = i;

  //       while (matrix[i] && matrix[i][j] === 'B') {
  //         if (matrix[i][j + 1] === 'B') {
  //           width++;
  //           j++;
  //         }
  //         else if (matrix[i + 1] && matrix[i + 1][j] === 'B') {
  //           height++;
  //           i++;
  //         }
  //         else {
  //           j++;
  //           i++;
  //         }
  //       }

  //       break;
  //     }
  //   }
  // }

  // console.log(y + 1 + Math.floor(height / 2), x + 1 + Math.floor(width / 2));
});

n = readline().split(' ').map(Number)[0]
r1 = r2 = c = -1
for (i = 0; i < n; i++) {
	a = readline()
	if (a.includes('B')) {
		if (r1==-1) r1 = i
		r2 = i
		c = (a.lastIndexOf('B')+a.indexOf('B'))/2
	}
}
print((r1+r2)/2+1, c+1)

var g = readline().split(" ");

var n = Number(g[0]);
var m = Number(g[1]);

var p_x = 0;
var p_y = 0;
for(i=0;i<n;i++){

    var k = readline();

    var B = k.indexOf("B");

    if(B != -1){
        var b = B;
        var side = 1;
        while(k[b] == "B"){
            side++;
            b++;
        }

        var point = Math.ceil(side/2);
        p_x = point + B;
        p_y = point + i;
        break;
    }
}

print(p_y, p_x);

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
	}
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			if(list[i][j] == "B"){
				var add = -1;
				for(var k = 0; Math.max(i + k, j + k) < Math.min(H, W); k++){
					if(list[i + k][j + k] == "B"){
						add++;
					}else{
						break;
					}
				}
				add = Math.ceil(add / 2);
				myout((i + 1 + add) + " " + (j + 1 + add));
				return;
			}
		}
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
	}
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			if(list[i][j] == "B"){
				var add = 0;
				for(var k = 1; Math.max(i + k, j + k) < Math.min(H, W); k++){
					if(list[i + k][j + k] == "B"){
						add++;
					}else{
						break;
					}
				}
				add = Math.floor(add / 2);
				myout((i + 1 + add) + " " + (j + 1 + add));
				return;
			}
		}
	}
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];

print(output(k, n))

function output(k, n) {
    var arr = []
    for (var i = 0; i < n; i++) {
        var string = readline();
        arr.push(string);
    }
    var edjeX1 = 0;
    var edjeX2 = parseInt(k) - 1;
    var edjeY1 = 0;
    var edjeY2 = parseInt(n) - 1;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < k; j++) {
            if (arr[i][j] === "B" && edjeX1 === 0) {
                edjeX1 = j;
            }
            if (arr[i][j] === "W" && j > 0 && arr[i][j-1] === "B" && edjeX2 === parseInt(k) - 1) {
                edjeX2 = j;
            }
            if (arr[i][j] === "B" && edjeY1 === 0) {
                edjeY1 = i;
            }
            if (arr[i][j] === "W" && i > 0 && arr[i-1][j] === "B" && edjeY2 === parseInt(n) - 1) {
                edjeY2 = i;
            }
        }
    }
    return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];

print(output(k, n))

function output(k, n) {
    var arr = []
    for (var i = 0; i < n; i++) {
        var string = readline();
        arr.push(string);
    }
    var edjeX1 = 0;
    var edjeX2 = parseInt(k) - 1;
    var edjeY1 = 0;
    var edjeY2 = parseInt(n) - 1;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < k; j++) {
            if (arr[i][j] === "B" && edjeX1 === 0) {
                edjeX1 = j;
            }
            if (arr[i][j] === "W" && j > 0 && arr[i][j-1] === "B" && edjeX2 === parseInt(k) - 1) {
                edjeX2 = j-1;
            }
            if (arr[i][j] === "B" && edjeY1 === 0) {
                edjeY1 = i;
            }
            if (arr[i][j] === "W" && i > 0 && arr[i-1][j] === "B" && edjeY2 === parseInt(n) - 1) {
                edjeY2 = i-1;
            }
        }
    }
    return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];

print(output(k, n))

function output(k, n) {
    var arr = []
    for (var i = 0; i < n; i++) {
        var string = readline();
        arr.push(string);
    }
    var edjeX1 = 0;
    var edjeX2 = 0;
    var edjeY1 = 0;
    var edjeY2 = 0;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < k; j++) {
            if (arr[i][j] === "B" && edjeX1 === 0) {
                edjeX1 = j;
            }
            if (arr[i][j] === "W" && arr[i][j-1] && arr[i][j-1] === "B" && edjeX2 === 0) {
                edjeX2 = j;
            }
            if (arr[i][j] === "B" && edjeY1 === 0) {
                edjeY1 = i;
            }
            if (arr[i][j] === "W" && i > 0 && arr[i-1][j] === "B" && edjeY2 === 0) {
                edjeY2 = i;
            }
        }
    }
    return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();
}

var firstLine = readline();
var n = firstLine.split(" ")[0];
var k = firstLine.split(" ")[1];

print(output(k, n))

function output(k, n) {
    var arr = []
    for (var i = 0; i < n; i++) {
        var string = readline();
        arr.push(string);
    }
    var edjeX1 = 0;
    var edjeX2 = parseInt(k) - 1;
    var edjeY1 = 0;
    var edjeY2 = parseInt(n) - 1;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < k; j++) {
            if (arr[i][j] === "B" && edjeX1 === 0) {
                edjeX1 = j;
            }
            if (arr[i][j] === "W" && arr[i][j-1] && arr[i][j-1] === "B" && edjeX2 === 0) {
                edjeX2 = j;
            }
            if (arr[i][j] === "B" && edjeY1 === 0) {
                edjeY1 = i;
            }
            if (arr[i][j] === "W" && i > 0 && arr[i-1][j] === "B" && edjeY2 === 0) {
                edjeY2 = i;
            }
        }
    }
    return (Math.ceil((edjeY1 + edjeY2)/2)).toString() + ' ' + (Math.ceil((edjeX1 + edjeX2)/2)).toString();
}


(function () {

var n = parseInt(readline());

var first;
var second;
for (var i = 0; i < n; i++) {
    var row = readline().split('');
    if (!first) {
        first = row[0];
        second = row[1];

        if (first === second) {
            print('NO');
            return;
        }
    }

    for (var j = 0; j < row.length; j++) {
        if (i === j || row.length - 1 - i ===  j) {
            if (row[j] !== first) {
                print('NO');
                return;
            }
        } else {
            if (row[j] !== second) {
                print('NO');
                return;
            }
        }
    }
}

print('YES');
})();

print(function(n) {
	var q = [];
	for (var i = 0; i < n; i++)
		q.push(readline().split(''));
	var a = q[0][0];
	var b = q[0][1];
	if(a===b) return 'NO';
	for (var i = 0; i < n; i++)
		for (var j = 0; j < n; j++)
			if (i === j || i === n - j - 1) {
				if (q[i][j] !== a) return 'NO';
			} else {
				if (q[i][j] !== b) return 'NO';
			}

	return 'YES';

}(+readline()));

var squareSize = Number(readline())

var index = 0
var ans = true
var xLetter
var oLetter

for (var i = 0; i < squareSize; i++) {
  var line = readline()
  if (i === 0) {
    xLetter = line[0]
    oLetter = line[1]
    if (xLetter === oLetter) {
      ans = false
      break;
    }
  }

  for (var j = 0; j < line.length; j++) {
    if (j === index || j === line.length - 1 - index) {
      if (line[j] !== xLetter) {
        ans = false
      }
    } else {
      if (line[j] !== oLetter) {
        ans = false
      }
    }

    if (ans === false) {
      break;
    }
  }

  if (ans === false) {
    break;
  }

  if (i < Math.floor(squareSize / 2)) {
    index += 1
  } else {
    index -= 1
  }
}

if (ans) {
  print('YES')
} else {
  print('NO')
}

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
// txt.shift();
for (let index = 0; index < txt.length; index++) {
    if (!isNaN(txt[index])) {
        let tab = []
        for (let i = index + 1; i < index + txt[index] * 1 + 1; i++) {
            tab.push(txt[i].split("").filter(data => {
                return data.length > 0
            }))
        }
        doit(tab)
    }

}

function doit(tab) {
    let s = tab[0][0],
        len = tab.length - 1;
    let arr = [],diag=[]
    tab.forEach(d => {
        d.forEach(data=>{
            if (!arr.includes(data)) {
                arr.push(data);
            }
            if(data==s){
                diag.push(data);
            }
        })
    })
    if (arr.length != 2 || diag.length!=tab.length*2-1) {
        console.log("NO");
        return;
    }

    let test = true
    tab.forEach((data, index) => {
        if (data[index] != s || data[len - index] != s) {
            test = false;
            return;
        }
    });
    if (test) {
        console.log("YES");
    } else {
        console.log("NO");
    }
}

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var n = parseInt(readline()),
		rows = [], letters = [], count = {};
	for (var r = 0; r < n; ++r) {
		var row = trim(readline());
		rows.push(row);
		for (var c = 0; c < n; ++c) {
			var ch = row.charAt(c);
			if (count[ch] === undefined) {
				letters.push(ch);
				count[ch] = 0;
			}
			count[ch] += 1;
		}
	}
	if (letters.length != 2) {
		print('NO');
		return;
	}
	var xCount = 2*n - 1;
	if (count[letters[0]] == xCount) {
		var x = letters[0];
	} else if (count[letters[1]] == xCount) {
		var x = letters[1];
	} else {
		print('NO');
		return;
	}
	for (var d = 0; d < n; ++d) {
		if (rows[d].charAt(d) != x || rows[d].charAt(n-1-d) != x) {
			print('NO');
			return;
		}
	}
	print('YES');
}

main();

;(function () {

	var n = +readline();
	var t = [];
	for (var i = 0; i < n; i++) t.push(readline());

	var g = t[0][0];
	var b = t[0][1];

	if (g == b) {
		print('NO');
		return;
	}

	for (var i = 0; i < n; i++)
		for (var j = 0; j < n; j++)
			if ( i == j || i + j == (n - 1) ) {

				if (t[i][j] != g) {
					print('NO');
					return;
				}

			} else {

				if (t[i][j] != b) {
					print('NO');
					return;
				}

			}

	print('YES');

}).call(this);

(function (){
    var i, j, n = parseInt(readline());
    var board = [];
    for(i = 0 ; i < n ; ++i){
        board[i] = readline();
    }

    var result = true;
    // first condition
    for( i = 0 ; result && i < n ; ++i){
        if ( board[i][i] != board[0][0] || board[i][n-1-i] != board[0][0] ){
            result = false;
        }
        for( j=0 ; result && j < n ; ++j){
            if ( j != i && j != n - 1 - i ){
                if ( board[i][j] == board[0][0] || board[i][j] != board[0][1] ){
                    result = false;
                }
            }
        }
    }
    if ( result ){
        print("YES");
    }else{
        print("NO");
    }
})();

(function () {

var num, n;
num = n = parseInt(readline());

var row = [];
var first;
var second;

while (num--) {
    row.push(readline().split(''));
}

first = row[0][0];
second = row[0][1];

if (first === second) {
    print('NO');
    return;
}

for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
        if (i === j || n - 1 === i + j) {
            if (row[i][j] !== first) {
                print('NO');
                return;
            }
        } else {
            if (row[i][j] !== second) {
                print('NO');
                return;
            }
        }
    }
}

print('YES');
})();

var n = parseInt(readline());

var flag = true;
var first;
var second;
var res = 'YES';
for (var i = 0; i < n; i++) {
    var row = readline().split('');
    if (!first) {
        first = row[0];
        second = row[1];

        if (first === second) {
            flag = false;
            res = 'NO';
        }
    }

    for (var j = 0; j < row.length; j++) {
        if (i === j || row.length - 1 - i ===  j) {
            if (row[j] !== first) {
                flag = false;
                res = 'NO';
                break;
            }
        } else {
            if (row[j] !== second) {
                flag = false;
                res = 'NO';
                break;
            }
        }
    }

    if (!flag) {
        break;
    }
}

print(res);

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
// txt.shift();
for (let index = 0; index < txt.length; index++) {
    if (!isNaN(txt[index])) {
        let tab = []
        for (let i = index + 1; i < index + txt[index] * 1 + 1; i++) {
            tab.push(txt[i].split("").filter(data => {
                return data.length > 0
            }))
        }
        doit(tab)
    }

}

function doit(tab) {
    let s = tab[0][0],
        len = tab.length - 1;
    let arr = []
    tab.forEach(d => {
        d.forEach(data=>{
            if (!arr.includes(data)) {
                arr.push(data);
            }
        })
    })
    if (arr.length != 2) {
        console.log("NO");
        return;
    }

    let test = true
    tab.forEach((data, index) => {
        if (data[index] != s || data[len - index] != s) {
            test = false;
            return;
        }
    });
    if (test) {
        console.log("YES");
    } else {
        console.log("NO");
    }
}

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
// txt.shift();
for (let index = 0; index < txt.length; index ++) {
    if(!isNaN(txt[index])){
        let tab=[]
        for (let i = index+1; i < index+txt[index]*1+1; i++) {
            tab.push(txt[i].split("").filter(data=>{return data.length>0}))
        }
        doit(tab)
    }

}

function doit(tab) {
   let s=tab[0][0],len=tab.length-1;
   let test=true
   tab.forEach((data,index) => {
       if(data[index]!=s || data[len-index]!=s){
           test=false;
           return;
       }
   });
   if(test){
       console.log("YES");
   }else{
       console.log("NO");
   }

}

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0
});
// txt.shift();
for (let index = 0; index < txt.length; index ++) {
    if(!isNaN(txt[index])){
        let tab=[]
        for (let i = index+1; i < index+txt[index]*1+1; i++) {
            tab.push(txt[i].split("").filter(data=>{return data.length>0}))
        }
        doit(tab)
    }

}

function doit(tab) {
   let s=tab[0][0],len=tab.length-1;
   let ss=tab[0][1];
   let test=true
   tab.forEach((data,index) => {
       if(data[index]!=s || data[len-index]!=s){
           test=false;
           return;
       }
       data.forEach((d,i)=>{
           if(i!=index && i!=len-index && d!=ss){
               test=false;
               return;
           }
       })
   });
   if(test){
       console.log("YES");
   }else{
       console.log("NO");
   }

}

print(function(n) {
	var q = [];
	for (var i = 0; i < n; i++)
		q.push(readline().split(''));
	var a = q[0][0];
	var b = q[0][1];
	for (var i = 0; i < n; i++)
		for (var j = 0; j < n; j++)
			if (i === j || i === n - j) {
				if (q[i][j] !== a) return 'NO';
			} else {
				if (q[i][j] !== b) return 'NO';
			}

	return 'YES';

}(+readline()));

print(function(n) {
	var q = [];
	for (var i = 0; i < n; i++)
		q.push(readline().split(''));
	var a = q[0][0];
	var b = q[0][1];
	for (var i = 0; i < n; i++)
		for (var j = 0; j < n; j++)
			if (i === j || i === n - j - 1) {
				if (q[i][j] !== a) return 'NO';
			} else {
				if (q[i][j] !== b) return 'NO';
			}

	return 'YES';

}(+readline()));

(function (){
    var i, j, n = parseInt(readline());
    var board = [];
    for(i = 0 ; i < n ; ++i){
        board[i] = readline();
    }

    var result = true;
    // first condition
    for( i = 0 ; result && i < n ; ++i){
        if ( board[i][i] != board[0][0] || board[i][n-1-i] != board[0][0] ){
            result = false;
        }
        for( j=0 ; result && j < n ; ++j){
            if ( j != i && j != n - 1 - i ){
                if ( board[i][j] == board[0][0] ){
                    result = false;
                }
            }
        }
    }
    if ( result ){
        print("YES");
    }else{
        print("NO");
    }
})();

(function () {

var n = parseInt(readline());

var row = [];
var first;
var second;

while (n--) {
    row.push(readline().split(''));
}

first = row[0][0];
second = row[1][1];

if (first === second) {
    print('NO');
    return;
}

for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
        if (i === j || n - 1 === i + j) {
            if (row[i][j] !== first) {
                print('NO');
                return;
            }
        } else {
            if (row[i][j] !== second) {
                print('NO');
                return;
            }
        }
    }
}

print('YES');
})();

(function () {

var n = parseInt(readline());

var row = [];
var first;
var second;

while (n--) {
    row.push(readline().split(''));
}

first = row[0][0];
second = row[0][1];

if (first === second) {
    print('NO');
    return;
}

for (var i = 0; i < n; i++) {
    for (var j = 0; j < n; j++) {
        if (i === j || n - 1 === i + j) {
            if (row[i][j] !== first) {
                print('NO');
                return;
            }
        } else {
            if (row[i][j] !== second) {
                print('NO');
                return;
            }
        }
    }
}

print('YES');
})();

var n = parseInt(readline());

var flag = true;
var first;
var second;
for (var i = 0; i < n; i++) {
    var row = readline().split('');
    if (!first) {
        first = row[0];
        second = row[1];
    }

    for (var j = 0; j < row.length; j++) {
        if (i === j || row.length - 1 - i ===  j) {
            if (row[j] !== first) {
                flag = false;
                break;
            }
        } else {
            if (row[j] !== second) {
                flag = false;
                break;
            }
        }
    }

    if (!flag) {
        break;
    }
}

if (!flag) {
    print("NO");
} else {
    print("YES");
}

var n = parseInt(readline());

var flag = true;
var first;
var second;
for (var i = 0; i < n; i++) {
    var row = readline().split('');
    if (!first) {
        first = row[0][0];
        second = row[0][1];
    }

    for (var j = 0; j < row.length; j++) {
        if (i === j || row.length - 1 - i ===  j) {
            if (row[i][j] !== first) {
                flag = false;
                break;
            }
        } else {
            if (row[i][j] !== second) {
                flag = false;
                break;
            }
        }
    }

    if (!flag) {
        break;
    }
}

if (!flag) {
    print("NO");
} else {
    print("YES");
}


const myMap = new Set();
function findMin (currentPos){
	if (!myMap.has(currentPos)){
		return 0;
	}
	var left =  currentPos - 1, leftVal = -1;
	var right = currentPos + 1, rightVal = -1;
	while (left > 0 || right <= endPoint){
		if (!myMap.has(left) && left > 0){
			leftVal = Math.abs(currentPos-left);
			break;
		}
		else if (!myMap.has(right) && right <= endPoint){
			rightVal = Math.abs(currentPos-right);
			break;
		}
		left -= 1; right += 1;
	}
	return (leftVal != -1) ? leftVal : rightVal;
}
var queries = parseInt(readline());
for (var i = 0; i< queries;i++)
{
var discard = readline().split(' ');
var endPoint = parseInt(discard[0]);
readline().split(' ').forEach((val)=>{
	myMap.add(parseInt(val));
})
print(findMin(parseInt(discard[1])));
myMap.clear();
}

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const t = readInt(input)

  for(let count = 0; count < t; count ++) {
    const [n, s, k] = readInts(input, 2 * count)

    const ks = readInts(input, 2 * count + 1)

    sort(ks)

    let i = -2, j = -2
    if(s < n) i = ks.indexOf(s + 1)
    if(s > 1) j = ks.indexOf(s - 1)

    if(ks.indexOf(s) == -1) {
      wr(0)
      continue
    }

    if(i == -1 || j == -1) {
      wr(1)
      continue
    }
    let a = -1, b = -1

    let x = s + 1

    while(true && x <= n && i < k) {
      if(ks[i] != x) {
        a = x - s
        break
      }
      else {
        i++
        x++
      }
    }
    // wr(i, x)
    if(a == -1 && x <= n) a = x - s

    x = s - 1
    while(true && x>= 0 && j >= 0) {
      // wr(k[j], x, j)
      if(ks[j] != x) {
        b = s - x
        break
      }
      else {
        j--
        x--
      }
    }

    if(b == -1 && x > 0) b = s - x

    // wr(a, b)
    if(a == -1 && b == -1) wr(0)
    else if(a == -1) wr(b)
    else if(b == -1) wr(a)
    else wr(Math.min(a, b))
  }
}

const myMap = new Set();
function findMin (currentPos){
	if (!myMap.has(currentPos)){
		return 0;
	}
	var left =  currentPos - 1, leftVal = -1;
	var right = currentPos + 1, rightVal = -1;
	while (left > 0 || right <= endPoint){
		if (  left > 0 && !myMap.has(left) ){
			leftVal = Math.abs(currentPos-left);
			break;
		}
		else if (right <= endPoint && !myMap.has(right) ){
			rightVal = Math.abs(currentPos-right);
			break;
		}
		left -= 1; right += 1;
	}
	return (leftVal != -1) ? leftVal : rightVal;
}
var queries = parseInt(readline());
for (var i = 0; i< queries;i++)
{
var discard = readline().split(' ');
var endPoint = parseInt(discard[0]);
readline().split(' ').forEach((val)=>{
	myMap.add(parseInt(val));
})
print(findMin(parseInt(discard[1])));
myMap.clear();
}

function main() {
    var t = readline();
    for (var i = 0; i < t; i++) {
        findNext();
    }
}

function findNext() {
    var nsk = readline().split(' ');
    var n = +nsk[0];
    var s = +nsk[1];
    var k = +nsk[2];
    var ks = readline().split(' ');

    var ksObj = {}
    for (var d = 0; d < k; d++) {
        ksObj[ks[d]] = true;
    }

    for (var j = 0; j <= n; j++) {
        var plusJ = !ksObj[s + j] && s + j <= n;
        var minusJ = !ksObj[s - j] && s - j >= 1;

        if (plusJ || minusJ) {
            print(j);
            return;
        }
    }
}
main()

process.stdin.resume()
process.stdin.setEncoding('utf-8')

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const t = readInt(input)

  for(let count = 0; count < t; count ++) {
    const [n, s, k] = readInts(input, 2 * count)

    const ks = readInts(input, 2 * count + 1)

    sort(ks)

    let i = -2, j = -2
    if(s < n) i = ks.indexOf(s + 1)
    if(s > 1) j = ks.indexOf(s - 1)

    if(i == -1 || j == -1) {
      wr(1)
      continue
    }
    let a = -1, b = -1

    let x = s + 1

    while(true && x <= n && i < k) {
      if(ks[i] != x) {
        a = x - s
        break
      }
      else {
        i++
        x++
      }
    }
    // wr(i, x)
    if(a == -1 && x <= n) a = x - s

    x = s - 1
    while(true && x>= 0 && j >= 0) {
      // wr(k[j], x, j)
      if(ks[j] != x) {
        b = s - x
        break
      }
      else {
        j--
        x--
      }
    }

    if(b == -1 && x > 0) b = s - x

    // wr(a, b)
    if(a == -1 && b == -1) wr(0)
    else if(a == -1) wr(b)
    else if(b == -1) wr(a)
    else wr(Math.min(a, b))
  }
}


var n = +readline();
var s = readline();
var p = ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR'];
var min = n + 10;
var por = 0;
var ans = '';
for (var j=0; j<6; j++){
	var min1 = 0;
	for (var i=0; i<n; i++){
		if (s[i] != p[j][i%3]) min1++;
	}
	if (min1<min) {
		min = min1;
		por = j;
	}
}
for (var i=0; i<n; i++){
	ans += p[por][i%3];
}
print (min);
print (ans);

readline();
var input = readline();
var r = [0,0,0];var g = [0,0,0];var b = [0,0,0];

for(var i=0;i<input.length;i++){
var z = i;
if(z>2){z -=(Math.floor(z/3)*3);}
if(input[i]==="R"){r[z]++}
	if(input[i]==="G"){g[z]++}
	   if(input[i]==="B"){b[z]++}
}

var themax = 0;var RGB = [];

for(var s=0;s<3;s++){
var abc = "012".replace(s,"");var x = +abc[0];var y = +abc[1];
var calc = r[s]+g[x]+b[y];
if(themax<=calc){themax=calc;RGB[s]="R";RGB[x]="G";RGB[y]="B";}
calc = r[s]+g[y]+b[x];
if(themax<=calc){themax=calc;RGB[s]="R";RGB[y]="G";RGB[x]="B";}
}

var st="";themax=0;
for (var i = 0; i < input.length; i++) {
if(input[i]!==RGB[x]){themax++}
st+=RGB[x];x++;
if(x==3){x=0}
}

print(themax)
print(st)

function ansa(n,s){

  function permutator(inputArr) {
  var results = [];

  function permute(arr, memo) {
    var cur, memo = memo || [];

    for (var i = 0; i < arr.length; i++) {
      cur = arr.splice(i, 1);
      if (arr.length === 0) {
        results.push(memo.concat(cur));
      }
      permute(arr.slice(), memo.concat(cur));
      arr.splice(i, 0, cur[0]);
    }

    return results;
  }

  return permute(inputArr);
}

  var permuts = permutator(['R','G','B']);
  var ans = s;
  var mn = Infinity;

  for(var i = 0 ; i < permuts.length ; i++){

      var cst = 0;
      for(var j = 0 ; j < n ; j++){
          if(s[j] !== permuts[i][(j+1)%3])cst++;
      }
      if(cst < mn){
        mn = cst;
        ans = "";
        for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][(k+1)%3];
      }
  }

  print(mn);
  print(ans);

}

var n = parseInt(readline());
var str = readline();

ansa(n,str)

var cnt = 0;
var str = "";
var readliner = require('readline');
var rl = readliner.createInterface(process.stdin, process.stdout, null);
rl.on('line', function (cmd) {
                  //console.log('You just typed: '+cmd);
                  cnt++;
                  if (cnt > 1) str = cmd;
              }).on('close', main);

function solve(pat, str, ans, res) {
	//console.log(pat," ",str," ",ans," ",res);
	var N = Math.min(pat.length, str.length);
	var new_ans = 0;
	var new_res = "";
	for (var i=0; i<N; i++) {
		new_res += pat[i];
		if (str[i] !== pat[i])
			new_ans++;
	}
	if (pat.length < str.length)
		for (var i=pat.length; i<str.length; i++) {
			new_res += pat[i%3];
			if (str[i] !== pat[i%3])
				new_ans++;
		}
	//console.log(new_ans," ",new_res);
	if (new_ans < ans) {
		ans = new_ans;
		res.val = new_res;
	}
	return ans;
}

function main() {
	var res = {val:""};
	var ans = solve("RGB", str, 1000000000, res);
	ans = Math.min(ans, solve("RBG",str,ans,res));
	ans = Math.min(ans, solve("BRG",str,ans,res));
	ans = Math.min(ans, solve("BGR",str,ans,res));
	ans = Math.min(ans, solve("GBR",str,ans,res));
	ans = Math.min(ans, solve("GRB",str,ans,res));
	console.log(ans);
	process.stdout.write(res.val);

    //console.log(ans);
    //console.log(Q);

    //var x = 1.2345678;
    //console.log('x = ',Number(x).toFixed(5));

    process.exit(0);
};

//var lines = data.split(/\r?\n/);

function ansa(n,s){

  function FindAllPermutations(str, index, buffer) {
      if (typeof str == "string")
          str = str.split("");
      if (typeof index == "undefined")
          index = 0;
      if (typeof buffer == "undefined")
          buffer = [];
      if (index >= str.length)
          return buffer;
      for (var i = index; i < str.length; i++)
          buffer.push(ToggleLetters(str, index, i));
      return FindAllPermutations(str, index + 1, buffer);
  }

  function ToggleLetters(str, index1, index2) {
      if (index1 != index2) {
          var temp = str[index1];
          str[index1] = str[index2];
          str[index2] = temp;
      }
      return str.join("");
  }

  var permuts = FindAllPermutations("RGB");
  var ans = s;
  var mn = Infinity;

  for(var i = 0 ; i < 6 ; i++){

      var cst = 0;
      for(var j = 0 ; j < n ; j++){
          if(s[j] !== permuts[i][j%3])cst++;
      }
      if(cst < mn){
        mn = cst;
        ans = "";
        for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][k%3];
      }
  }

  print(mn);
  print(ans);

}

var n = parseInt(readline());
var str = readline();

ansa(n,str);

function ansa(n,s){

  function FindAllPermutations(str, index, buffer) {
      if (typeof str == "string")
          str = str.split("");
      if (typeof index == "undefined")
          index = 0;
      if (typeof buffer == "undefined")
          buffer = [];
      if (index >= str.length)
          return buffer;
      for (var i = index; i < str.length; i++)
          buffer.push(ToggleLetters(str, index, i));
      return FindAllPermutations(str, index + 1, buffer);
  }

  function ToggleLetters(str, index1, index2) {
      if (index1 != index2) {
          var temp = str[index1];
          str[index1] = str[index2];
          str[index2] = temp;
      }
      return str.join("");
  }

  var permuts = FindAllPermutations("RGB");
  var ans = "";
  var mn = Infinity;

  for(var i = 0 ; i < permuts.length ; i++){

      var cst = 0;
      for(var j = 0 ; j < n ; j++){
          if(s[j] !== permuts[i][j%3])cst++;
      }
      if(cst < mn){
        mn = cst;
        ans = "";
        for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][k%3];
      }
  }

  print(mn);
  print(ans);

}

var n = parseInt(readline());
var str = readline();

ansa(n,str)

function ansa(n,s){

  function FindAllPermutations(str, index, buffer) {
      if (typeof str == "string")
          str = str.split("");
      if (typeof index == "undefined")
          index = 0;
      if (typeof buffer == "undefined")
          buffer = [];
      if (index >= str.length)
          return buffer;
      for (var i = index; i < str.length; i++)
          buffer.push(ToggleLetters(str, index, i));
      return FindAllPermutations(str, index + 1, buffer);
  }

  function ToggleLetters(str, index1, index2) {
      if (index1 != index2) {
          var temp = str[index1];
          str[index1] = str[index2];
          str[index2] = temp;
      }
      return str.join("");
  }

  var permuts = FindAllPermutations("RGB");
  var ans = s;
  var mn = Infinity;

  for(var i = 0 ; i < permuts.length ; i++){

      var cst = 0;
      for(var j = 0 ; j < n ; j++){
          if(s[j] !== permuts[i][(j+1)%3])cst++;
      }
      if(cst < mn){
        mn = cst;
        ans = "";
        for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][(k+1)%3];
      }
  }

  print(mn);
  print(ans);

}

var n = parseInt(readline());
var str = readline();

ansa(n,str)

function ansa(n,str){

    var cnt = 0;
    var ans = '';

    if(n === 2){
      if(str[0] === str[1]){
        print("1");
        if(str[0] === "R")print("RG");
        else if(str[0] === "G")print("GR");
        else print("BG");
        return;
      }
    }
    if(str[0] === 'R' && str[1] === 'G'){
      var rgb = 'RGB';
      ans = 'RG';
      for(var i = 2 ; i < n ; i++){
        if(rgb[(i)%3] !== str[i]){
          cnt++;
          ans = ans + rgb[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'R' && str[1] === 'B'){
      var rbg = 'RBG';
      ans = 'RB';
      for(var i = 2 ; i < n ; i++){
        if(rbg[(i)%3] !== str[i]){
          cnt++;
          ans = ans + rbg[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'B' && str[1] === 'R'){
      var brg = 'BRG';
      ans = 'BR';
      for(var i = 2 ; i < n ; i++){
        if(brg[(i)%3] !== str[i]){
          cnt++;
          ans = ans + brg[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'B' && str[1] === 'G'){
      var bgr = 'BGR';
      ans = 'BG';
      for(var i = 2 ; i < n ; i++){
        if(bgr[(i)%3] !== str[i]){
          cnt++;
          ans = ans + bgr[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'G' && str[1] === 'R'){
      var grb = 'GRB';
      ans = 'GR';
      for(var i = 2 ; i < n ; i++){
        if(grb[(i)%3] !== str[i]){
          cnt++;
          ans = ans + grb[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'G' && str[1] === 'B'){
      var gbr = 'GBR';
      ans = 'GB';
      for(var i = 2 ; i < n ; i++){
        if(gbr[(i)%3] !== str[i]){
          cnt++;
          ans = ans + gbr[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'G' && str[1] === 'G'){
      var gbr = 'GBR';
      ans = 'G';
      for(var i = 1 ; i < n ; i++){
        if(gbr[(i)%3] !== str[i]){
          cnt++;
          ans = ans + gbr[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    }
    if(str[0] === 'R' && str[1] === 'R'){
      var rgb = 'RGB';
      ans = 'R';
      for(var i = 1 ; i < n ; i++){
        if(rgb[(i)%3] !== str[i]){
          cnt++;
          ans = ans + rgb[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    };
    if(str[0] === 'B' && str[1] === 'B'){
      var bgr = 'BGR';
      ans = 'B';
      for(var i = 1 ; i < n ; i++){
        if(bgr[(i)%3] !== str[i]){
          cnt++;
          ans = ans + bgr[(i)%3];
        }
        else ans = ans+str[i];
      }
      print(cnt);
      print(ans);
      return;
    };

}

var n = parseInt(readline());
var str = readline();

ansa(n,str);

function ansa(n,s){

  function FindAllPermutations(str, index, buffer) {
      if (typeof str == "string")
          str = str.split("");
      if (typeof index == "undefined")
          index = 0;
      if (typeof buffer == "undefined")
          buffer = [];
      if (index >= str.length)
          return buffer;
      for (var i = index; i < str.length; i++)
          buffer.push(ToggleLetters(str, index, i));
      return FindAllPermutations(str, index + 1, buffer);
  }

  function ToggleLetters(str, index1, index2) {
      if (index1 != index2) {
          var temp = str[index1];
          str[index1] = str[index2];
          str[index2] = temp;
      }
      return str.join("");
  }

  var permuts = FindAllPermutations("RGB");
  var ans = s;
  var mn = Infinity;

  for(var i = 0 ; i < permuts.length ; i++){

      var cst = 0;
      for(var j = 0 ; j < n ; j++){
          if(s[j] !== permuts[i][j%3])cst++;
      }
      if(cst < mn){
        mn = cst;
        ans = "";
        for(var k = 0 ; k < n ; k++)ans = ans + permuts[i][k%3];
      }
  }

  print(mn);
  print(ans);

}

var n = parseInt(readline());
var str = readline();

ansa(n,str)


process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    C();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x, y, k] = ti(readline().split(' '));

        let res = Math.ceil((k + (k*y) - 1) / (x-1));
        console.log(res + k);
    }
}

function C(){
    try{
        let t = pi(readline());
        while(t > 0){
            t--;
            let n = pi(readline());
            let a = ti(readline().split(' '));
            if(n === 0){
                console.log(0);
                continue;
            }

            let dp = new Array(n);
            for(let j = 0; j < n; j++){
                dp[j] = new Array(2);
                dp[j].fill(-1);
            }

            for(let i = 0; i < n; i++){
                if(i >= 2){
                    dp[i][0] = Math.min(dp[i-1][1]+a[i], dp[i-2][1]+a[i]+a[i-1]);
                    dp[i][1] = Math.min(dp[i-1][0], dp[i-2][0]);
                }else{
                    if(i === 0){
                        dp[i][0] = a[i];
                        dp[i][1] = a[i];
                    }else{
                        dp[i][0] = a[i] + a[i-1];
                        dp[i][1] = dp[i-1][0];
                    }
                }
            }

            //console.log(dp);
            console.log(Math.min(dp[n-1][0], dp[n-1][1]));

            let solve = (i, turn) => {
                console.log(i);
                if(i >= n)
                    return 0;

                if(i === n-1){
                    if(turn === 0)
                        return dp[i][turn] = a[i];
                    else
                        return dp[i][turn] = 0;
                }

                if(dp[i][turn] !== -1)
                    return dp[i][turn];

                if(turn === 0){
                    return dp[i][turn] = Math.min(a[i] + solve(i+1, 1), a[i]+a[i+1]+solve(i+2, 1));
                }else{
                    return dp[i][turn] = Math.min(solve(i+1, 0), solve(i+2, 0));
                }
            }

            //console.log(solve(0, 0));
        }
    }catch(e){
        console.log(e);
    }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
let standardInputString = "";
let currentLine = 0;

function readLine() {
  return standardInputString[currentLine++];
}

process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});

process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => line.trim());

  main();
});

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let unused = readLine();
    let bossArr = readLine()
      .split(" ")
      .map((el) => {
        return { a: parseInt(el), p: "" };
      });

    // set first to friend
    bossArr[0].p = "f";

    // set friend everywhere where boss is easy:
    bossArr = bossArr.map((el) => {
      if (el.a === 0) el.p = "f";

      return el;
    });

    // set me everywhere in 2 tiles if I can:

    let meCount = 0;
    for (let i = 0; i < bossArr.length; i++) {
      if (bossArr[i].p == "f") {
        meCount = 0;
        continue;
      } else if (meCount < 2) {
        bossArr[i].p = "m";
        meCount++;
      } else if (meCount >= 2) {
        bossArr[i].p = "f";
        meCount = 0;
      }
    }

    let res = bossArr.reduce(
      (acc, cur) => acc + (cur.a == 1 && cur.p == "f" ? 1 : 0),
      0
    );

    console.log(res);
  }
}

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var t = +inputs[0];
    for (let i = 0; i < t; i++) {
        var n = +inputs[i * 2 + 1];
        var a = inputs[i * 2 + 2].split(' ').map(v => +v);
        var b = [a[0], a[0] + a[1]];
        var c = [1e5, b[0]];
        for (let i = 2; i < n; i++) {
            b[i] = Math.min(a[i] + c[i - 1], a[i] + a[i - 1] + c[i - 2]);
            c[i] = Math.min(b[i - 1], b[i - 2]);
        }
        console.log(Math.min(b[n - 1], c[n - 1]));
    }
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    C();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x, y, k] = ti(readline().split(' '));

        let res = Math.ceil((k + (k*y) - 1) / (x-1));
        console.log(res + k);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));

        let count = 0;
        let i = 0;
        let turn = 0;
        while(i < n){
            if(turn === 0){
                if(a[i] === 1){
                    count += 1;
                    i += 1;
                }

                if(i < n && a[i] === 0){
                    i += 1;
                }
                turn = 1;
            }else{
                i += 1;
                if(i < n && a[i] === 1)
                    i += 1;

                turn = 0;
            }
        }
        console.log(count);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    C();
});

function readline() {
    return inputString[currentLine++];
}

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x, y, k] = ti(readline().split(' '));

        let res = Math.ceil((k + (k*y) - 1) / (x-1));
        console.log(res + k);
    }
}

function C(){
    try{
        let t = pi(readline());
        while(t > 0){
            t--;
            let n = pi(readline());
            let a = ti(readline().split(' '));
            if(n === 0){
                console.log(0);
                continue;
            }

            let dp = new Array(n);
            for(let j = 0; j < n; j++){
                dp[j] = new Array(2);
                dp[j].fill(-1);
            }

            let solve = (i, turn) => {
                if(i >= n)
                    return 0;

                if(i === n-1){
                    if(turn === 0)
                        return dp[i][turn] = a[i];
                    else
                        return dp[i][turn] = 0;
                }

                if(dp[i][turn] !== -1)
                    return dp[i][turn];

                if(turn === 0){
                    return dp[i][turn] = Math.min(a[i] + solve(i+1, 1), a[i]+a[i+1]+solve(i+2, 1));
                }else{
                    return dp[i][turn] = Math.min(solve(i+1, 0), solve(i+2, 0));
                }
            }

            console.log(solve(0, 0));
        }
    }catch(e){
        console.log(e);
    }
}