const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
    if (foundFirstBlack === -1) {
      if (found[i - 1]) {
        for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
          closeForS.add(cs)
        }
      }
      i++;
      continue;
    }
    else {found[i] = [foundFirstBlack]}

    // if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundLastBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (

      (Object.keys(found).length !== l1 && closeForS.size === l2) ||
      (Object.keys(found).length === l1 && closeForS.size !== l2)

  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var blankLines1 = 0, blankLines2 = 0;
var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) {
        if (rc) {
            blankLines1 ++;
        } else {
            blankLines2 ++;
        }
    }
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

if ((blankLines2 === 0 && blankLines1 > 0) || (blankLines2 > 0 && blankLines1 === 0)) output = -1;

print(output);

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
    if (foundFirstBlack === -1) {
      if (i === l1 - 1) {
        for (cs = 0; cs <= l2; cs++) {
          closeForS.add(cs)
        }
      }
      i++;
      continue;
    }
    else {found[i] = [foundFirstBlack]}

    // if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (

      (Object.keys(found).length !== l1 && closeForS.size === l2) ||
      (Object.keys(found).length === l1 && closeForS.size !== l2)

  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let NOTFOUNDBLACK = false;
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
      else {found[i] = [foundFirstBlack]}

    if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack > foundFirstBlack && foundFirstWhiteInBlack < foundLastBlack) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (
    (Object.keys(test).length !== l1) && FOUNDBLACK
  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let NOTFOUNDBLACK = false;
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
      else {found[i] = [foundFirstBlack]}

    if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (
    (Object.keys(test).length !== l1 || closeForS.size !== l2) && FOUNDBLACK
  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
    if (foundFirstBlack === -1) {
      for (cs = 0; cs <= l2; cs++) {
        closeForS.add(cs)
      }
      i++;
      continue;
    }
    else {found[i] = [foundFirstBlack]}

    // if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundLastBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (

      (Object.keys(found).length !== l1 && closeForS.size === l2) ||
      (Object.keys(found).length === l1 && closeForS.size !== l2)

  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
    if (foundFirstBlack === -1) {
      if (i === l1 - 1) {
        for (cs = 0; cs <= l2; cs++) {
          closeForS.add(cs)
        }
      }
      i++;
      continue;
    }
    else {found[i] = [foundFirstBlack]}

    // if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundLastBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (

      (Object.keys(found).length !== l1 && closeForS.size === l2) ||
      (Object.keys(found).length === l1 && closeForS.size !== l2)

  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
    if (foundFirstBlack === -1) {
      if (i === l1 - 1) {
        for (cs = 0; cs <= l2; cs++) {
          closeForS.add(cs)
        }
      }
      i++;
      continue;
    }
    else {found[i] = [foundFirstBlack]}

    // if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (
    (
      (Object.keys(found).length !== l1 && closeForS.size !== l2)
      // (Object.keys(found).length === l1 && closeForS.size !== l2)
    ) && FOUNDBLACK
  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
let l1, l2;
let test = [];
rl.on('line', (line) => {
  if (l1 === undefined && l2 === undefined) {
    const [l11, l22] = line.split(' ');

    l1 = +l11;
    l2 = +l22;
  } else {
    test.push(line.split(''));
  }
}).on('close', () => {
  let FOUNDBLACK = false;
  // кол-во островков и серверных магнитов
  let N = 0;
  // i => строка, j = столбец
  let i = 0;
  const found = {}; // строки
  const closeForS = new Set();

  while (i < l1) {
    const foundFirstBlack = test[i].indexOf('#');

    // if (foundFirstBlack === -1) {i++; NOTFOUNDBLACK = true; continue;}
    if (foundFirstBlack === -1) {
      if (i === l1 - 1) {
        for (cs = 0; cs <= l2; cs++) {
          closeForS.add(cs)
        }
      }
      i++;
      continue;
    }
    else {found[i] = [foundFirstBlack]}

    // if (NOTFOUNDBLACK) {N = -1; break;}

    FOUNDBLACK = true;

    const foundLastBlack = test[i].lastIndexOf('#');
    found[i].push(foundLastBlack);

    if (closeForS.has(foundFirstBlack) || closeForS.has(foundFirstBlack)) {N = -1; break;}

    const foundFirstWhiteInBlack = test[i].indexOf('.', foundFirstBlack);
    if (foundFirstWhiteInBlack >= found[i][0] && foundFirstWhiteInBlack <= found[i][1]) {N = -1; break;}

    if (found[i - 1] !== undefined) {
      for (cs = found[i - 1][0]; cs <= found[i - 1][1]; cs++) {
        if (cs < found[i][0] || cs > found[i][1]) closeForS.add(cs)
      }
    }

    if (
      found[i - 1] === undefined ||
      (foundFirstBlack < found[i - 1][0] && foundLastBlack < found[i - 1][0]) ||
      (foundFirstBlack > found[i - 1][1] && foundLastBlack > found[i - 1][1])
    ) {
      N++;
    }

    if (i === l1 -1) {
      for (cs = foundFirstBlack; cs <= foundLastBlack; cs++) {
        closeForS.add(cs)
      }
    }

    i++;
  }

  if (
    (
      (Object.keys(found).length !== l1 && closeForS.size === l2) ||
      (Object.keys(found).length === l1 && closeForS.size !== l2)
    ) && FOUNDBLACK
  ) {
    N = -1;
  }

  process.stdout.write(N.toString());
});

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var blankLines1 = 0, blankLines2 = 0;
var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) {
        if (rc) {
            blankLines1 ++;
        } else {
            blankLines2 ++;
        }
    }
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

if ((blankLines1 === 0 && blankLines2 === 0) || (blankLines1 > 1 && blankLines2 > 1)) output = -1;

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        if (g === '#') t2 = 1;
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fill = function(y, x) {
    var fillStack = [];
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 || grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t === 0 && output === 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t === 0 && output !== 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output); //

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    for (var x = 0; x < size[1]; x ++) {
        grid2.push(0); // empty
    }
}

var recur = function(x, y) {
    if (grid[y][x] === '#' && grid2[y][x] === 0) {
        grid2[y][x] = 1;
        if (size[0] > x + 1) recur(x + 1, y);
        if (1 <= x) recur(x - 1, y);
        if (size[1] > y + 1) recur(x, y + 1);
        if (1 <= y) recur(x, y - 1);
        return true;
    }
    return false;
};

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    if ('#.# #..# #...# #....# #.....# #......# #.......#'.includes(grid[y])) {
        output = -1;
        break;
    }
    for (var x = 0; x < size[1]; x ++) {
        if (recur(x, y)) output ++;
    }
}

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);//

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 || grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t === 0 && output === 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t === 0 && output === 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var blankLines1 = 0, blankLines2 = 0;
var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) {
        if (rc) {
            blankLines1 ++;
        } else {
            blankLines2 ++;
        }
    }
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

if ((blankLines1 !== 0 || blankLines2 !== 0) || (blankLines1 > 1 && blankLines2 > 1)) output = -1;

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var blankLines1 = 0, blankLines2 = 0;
var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) {
        if (rc) {
            blankLines1 ++;
        } else {
            blankLines2 ++;
        }
    }
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

if ((blankLines1 !== 0 || blankLines2 !== 0) && (blankLines1 <= 1 && blankLines2 <= 1)) output = -1;

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    for (var x = 0; x < size[1]; x ++) {
        grid2.push(0); // empty
    }
}

var recur = function(x, y) {
    if (grid[y][x] === '#' && grid[y][x] === 0) {
        grid[y][x] = 1;
        if (size[0] > x + 1) recur(x + 1, y);
        if (1 <= x) recur(x - 1, y);
        if (size[1] > y + 1) recur(x, y + 1);
        if (1 <= y) recur(x, y - 1);
        return true;
    }
    return false;
};

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (recur(x, y)) output ++;
    }
}

// rule 3 violation test
/*for (var y = 0; y < size[0]; y ++) {
    var test = 0; //
    for (var x = 0; x < size[1]; x ++) {
        if (grid[y][x] === '#') {
            if (test === 0) {
                test = 1; // hit black tile
            } else {
                output = -1;
            }
        } else if (test === 1) {
            test = 2; // hit white tile
        }
    }
}*/

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var blankLines = 0;
var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) blankLines ++;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

if (blankLines === 1) output = -1;

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    for (var x = 0; x < size[1]; x ++) {
        grid2.push(0); // empty
    }
}

var recur = function(x, y) {
    if (grid[y][x] === '#' && grid[y][x] === 0) {
        grid[y][x] = 1;
        if (size[0] > x + 1) recur(x + 1, y);
        if (1 <= x) recur(x - 1, y);
        if (size[1] > y + 1) recur(x, y + 1);
        if (1 <= y) recur(x, y - 1);
        return true;
    }
    return false;
};

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (recur(x, y)) output ++;
    }
}

// rule 3 violation test
for (var y = 0; y < size[0]; y ++) {
    var test = 0; //
    for (var x = 0; x < size[1]; x ++) {
        if (grid[y][x] === '#') {
            if (test === 0) {
                test = 1; // hit black tile
            } else {
                output = -1;
            }
        } else if (test === 1) {
            test = 2; // hit white tile
        }
    }
}

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var recur = function(x, y) {
    if (grid[y][x] === '#' && grid2[y][x] === 0) {
        grid2[y][x] = 1;
        if (size[1] > x + 1) recur(x + 1, y);
        if (x - 1 >= 0) recur(x - 1, y);
        if (size[0] > y + 1) recur(x, y + 1);
        if (y - 1 >= 0) recur(x, y - 1);
        return true;
    }
    return false;
};

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (recur(x, y)) output ++;
    }
}

var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t === 0 || output === 0) output = -1;
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var fillStack = [];
var fill = function(y, x) {
    fillStack.push([y, x]);
    while(fillStack.length > 0) {
        var t = fillStack.pop();
        y = t[0];
        x = t[1];
        if (y < 0 || y >= size[0] || x < 0 || x >= size[1]) continue;
        if (grid2[y][x] === 1 || grid[y][x] === '.') continue;
        grid2[y][x] = 1;
        fillStack.push([y + 1, x]);
        fillStack.push([y - 1, x]);
        fillStack.push([y, x + 1]);
        fillStack.push([y, x - 1]);
    }
}

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (grid2[y][x] === 0 && grid[y][x] === '#') {
            output ++;
            fill(y, x);
        }
    }
}

var blankLines1 = 0, blankLines2 = 0;
var check = function(rc, n) {
    var t = 0;
    var t2 = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]) && output !== -1; i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') {
                t = 1;
                t2 = 1;
            }
            break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                }
            break;
        }
    }
    if (t2 === 0 && output !== 0) {
        if (rc) {
            blankLines1 ++;
        } else {
            blankLines2 ++;
        }
    }
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

if ((blankLines1 !== 0 || blankLines2 !== 0) || !(blankLines1 > 1 && blankLines2 > 1)) output = -1;

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var recur = function(x, y) {
    if (grid[y][x] === '#' && grid2[y][x] === 0) {
        grid2[y][x] = 1;
        if (size[1] > x + 1) recur(x + 1, y);
        if (x - 1 >= 0) recur(x - 1, y);
        if (size[0] > y + 1) recur(x, y + 1);
        if (y - 1 >= 0) recur(x, y - 1);
        return true;
    }
    return false;
};

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (recur(x, y)) output ++;
    }
}

var check = function(rc, n) {
    var t = 0;
    for (var i = 0; i < (rc ? size[1] : size[0]); i ++) {
        var g = rc ? grid[n][i] : grid[i][n];
        switch(t) {
            case 0: if (g === '#') t = 1; break;
            case 1: if (g === '.') t = 2; break;
            case 2:
                if (g === '#') {
                    output = -1;
                    break;
                }
            break;
        }
    }
};

for (var y = 0; y < size[0] && output !== -1; y ++)
    check(true, y);
for (var x = 0; x < size[1] && output !== -1; x ++)
    check(false, x);

print(output);

var size = readline().split(' ').map(x => parseInt(x));
var grid = [], grid2 = [];
for (var y = 0; y < size[0]; y ++) {
    grid.push(readline());
    grid2.push([]);
    for (var x = 0; x < size[1]; x ++)
        grid2[y].push(0);
}

var recur = function(x, y) {
    if (grid[y][x] === '#' && grid2[y][x] === 0) {
        grid2[y][x] = 1;
        if (size[0] > x + 1) recur(x + 1, y);
        if (1 <= x) recur(x - 1, y);
        if (size[1] > y + 1) recur(x, y + 1);
        if (1 <= y) recur(x, y - 1);
        return true;
    }
    return false;
};

var output = 0;
for (var y = 0; y < size[0]; y ++) {
    for (var x = 0; x < size[1]; x ++) {
        if (recur(x, y)) output ++;
    }
}

print(output);


const MEMORY = [];
let MEMORY_INDEX = 0;
function print() {
   console.log.apply(null, arguments);
}
function readline() {
   return MEMORY[MEMORY_INDEX++];
}

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
   MEMORY.push(line);
});

RL.on('close', solve);

function solve() {
   const T = Number.parseInt(readline(), 10);
   for (let i = 0; i < T; ++i) {
      let [str, int, exp] = readline().split(' ').map(n => Number.parseInt(n, 10));
      if (str + exp <= int) {
         print(0);
         continue;
      }
      let maxStr = str + exp;
      let minStr = Math.max((str + exp + int + 2) >> 1, str);
      print(maxStr - minStr + 1);
   }
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();

    while (T --> 0) {
        var input = rdArN();
        var str = input[0];
        var int = input[1];
        var exp = input[2];

        var s = str+int+exp;
        var maxStr = str + exp;
        var minStr = Math.max(str, (s >> 1) + 1);
        var res = 0;
        if (maxStr >= minStr) {
            res = maxStr - minStr + 1;
        }

        pr(res);
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  for (let i = 1; i < lines.length; i++) {
    const parts = lines[i].split(' ');
    if (parts.length === 3) {
      console.log(creating(parseInt(parts[0], 10), parseInt(parts[1], 10), parseInt(parts[2], 10)));
    }
  }
});

function creating(str, int, exp) {
  if (str + exp <= int) return 0;
  const diff = str + exp - int;
  return diff % 2 === 0 ? Math.min(Math.floor(diff / 2), exp + 1) : Math.min(1 + (Math.floor(diff / 2)), exp + 1);
}

'use strict';
const io = (function() {
  process.stdin.resume(); process.stdin.setEncoding('utf-8');
  let inputString = '', currentLine = 0, curTok = 0, input = [];
  function _check() { if (currentLine >= input.length) throw 'EOF!'; }
  process.stdin.on('data', data => { inputString += data; });
  process.stdin.on('end', _ => {
      for (const i of inputString.split('\n')) { input.push(i.split(' ')); }
      main();
  });
  function nextLine() {
    _check();
    const ret = input[currentLine++].slice(curTok).join(' ');
    curTok = 0;
    return ret;
  }
  function next() {
    _check();
    while (curTok == input[currentLine].length) {
      currentLine++;
      curTok = 0;
      _check()
    }
    return input[currentLine][curTok++];
  }
  function nextInt() { return parseInt(next()); }
  return {
    nextLine: nextLine,
    next: next,
    nextInt: nextInt,
  };
})();

function poss(s, i, e, tar) {
  if (tar < s) return false;
  const need = tar - s;
  if (need > e) return false;
  s += need;
  i += e - need;
  return s > i;
}

function deal() {
  let s = io.nextInt();
  let i = io.nextInt();
  let e = io.nextInt();
  let ans = -1;
  if (s + e <= i) {
    ans = 0;
  } else {
    //lowest value that is possible
    let lo = 0;   //not possible
    let hi = s+e; //possible
    while (lo < hi - 1) {
      let guess = Math.floor((lo + hi) / 2);
      if (poss(s, i, e, guess)) {
        hi = guess;
      } else {
        lo = guess;
      }
    }
    ans = s+e - hi + 1;
  }
  console.log(ans);
}

function main() {
  let T = io.nextInt();
  while (T > 0) {
    deal();
    T--;
  }
}

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = "";
process.stdin.on('data', function(chunk) {
  arr += chunk;
});

process.stdin.on('end', () => {
  arr = arr.split("\n");
  const noOfQueries = parseInt(arr.shift())
  for(let i = 0; i < noOfQueries; i++){
    // if exp === 0
    // else
    const queries = arr[i].split(' ');
    const str = parseInt(queries[0])
    const intellect = parseInt(queries[1])
    let exp = parseInt(queries[2])
    if(str == intellect){
      if(exp == 0){
        console.log(0)
      }
      else console.log(Math.ceil(exp / 2))
    }
    else if(str < intellect){
      if(intellect - str >= exp) console.log(0)
      else{
        exp = exp - intellect + str
        console.log(Math.ceil(exp / 2))
      }
    }
    else{
      if(str - intellect > exp) console.log(exp + 1)
      else if (str - intellect == exp) console.log(exp)
      else{
        const diff = str - intellect
        console.log(Math.ceil((exp - diff) / 2) + diff)
      }
    }
  }
})

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();

    while (T --> 0) {
        var input = rdArN();
        var str = input[0];
        var int = input[1];
        var exp = input[2];

        var s = str+int+exp;
        var minStr = (s >> 1) + 1;
        var maxInt = s - minStr;

        var freeInt = maxInt - int + 1;

        pr(freeInt > 0 ? freeInt : 0);
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

process.stdin.resume()
process.stdin.setEncoding('utf8')
let arr = "";
process.stdin.on('data', function(chunk) {
  arr += chunk;
});

process.stdin.on('end', () => {
  arr = arr.split("\n");
  const noOfQueries = parseInt(arr.shift())
  for(let i =0; i < noOfQueries; i++){
    // if exp === 0
    // else
    const queries = arr[i].split(' ');
    const str = parseInt(queries[0])
    const int = parseInt(queries[1])
    let exp = parseInt(queries[2])
    if(str == int){
      if(exp == 0){
        console.log(0)
      }
      else console.log(Math.ceil(exp / 2))
    }
    else if(str < int){
      if(int - str >= exp) console.log(0)
      else{
        exp = exp - int + str
        console.log(Math.ceil(exp / 2))
      }
    }
    else{
      exp = exp + str - int
      console.log(Math.ceil(exp / 2))
    }
  }
})

const MEMORY = [];
let MEMORY_INDEX = 0;
function print() {
   console.log.apply(null, arguments);
}
function readline() {
   return MEMORY[MEMORY_INDEX++];
}

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
   MEMORY.push(line);
});

RL.on('close', solve);

function solve() {
   const T = Number.parseInt(readline(), 10);
   for (let i = 0; i < T; ++i) {
      let [str, int, exp] = readline().split(' ').map(n => Number.parseInt(n, 10));
      let maxDiff = str + exp - int + 1;
      if (maxDiff <= 1) {
         print(0);
      } else {
         print((maxDiff >> 1));
      }
   }
}

const MEMORY = [];
let MEMORY_INDEX = 0;
function print() {
   console.log.apply(null, arguments);
}
function readline() {
   return MEMORY[MEMORY_INDEX++];
}

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
   MEMORY.push(line);
});

RL.on('close', solve);

function solve() {
   const T = Number.parseInt(readline(), 10);
   for (let i = 0; i < T; ++i) {
      let [str, int, exp] = readline().split(' ').map(n => Number.parseInt(n, 10));
      if (str + exp <= int) {
         print(0);
         continue;
      }
      let maxStr = str + exp;
      let minStr = (str + exp + int + 2) >> 1;
      print(maxStr - minStr + 1);
   }
}


(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let i="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{i+=t})),process.stdin.on("end",(e=>{s=i.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312)),i=r(719);o.default.runMain((function(){let[t]=o.default.nextNumbers(),e=o.default.nextNumbers(),r=e.max(),n=-1;for(let t of e)t!=r&&(n=-1!=n?i.gcd(r-t,n):r-t);let s=0;for(let t of e)s+=(r-t)/n;o.default.puts(s+" "+n)}))},719:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)}},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
// import { gcd } from './numberTheory'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let m = a.max()
//
//   let r = -1
//
//   for (let x of a) {
//     if (x == m) {
//       continue
//     }
//     if (r == -1) {
//       r = m - x
//       continue
//     }
//     r = gcd(m - x, r)
//   }
//
//   let s = 0
//
//   for (let x of a) {
//     s += (m - x) / r
//   }
//
//   io.puts(s + " " + r)
// }
//
// // io.runEachTest(main)
// io.runMain(main)

'use strict'

const n = parseInt(readline());
let m = readline().split(' ').map(Number);

const gcd = (a,b) => {
    if (a < b) { const c = a; a = b; b = c; }
    while(b) { const c = a % b; a = b; b = c; }
    return a;
};

m = m.sort((a, b) => b - a);
const d = m.slice(1).map(i => m[0] - i).filter(Boolean);
const z = d.slice(1).reduce((r, i) => gcd(r, i), d[0]);
const y = d.reduce((r, i) => r + i, 0) / z;
write(y + ' ' + z);

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let i="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{i+=t})),process.stdin.on("end",(e=>{s=i.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312)),i=r(719);o.default.runMain((function(){let[t]=o.default.nextNumbers(),e=o.default.nextNumbers(),r=e.max(),n=-1;for(let t of e)t!=r&&(n=-1!=n?i.gcd(r-t,n):r-t);let s=0;for(let t of e)s+=(r-t)/n;o.default.puts(s+" "+n)}))},719:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)}},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// numberTheory.ts

// function gcd(a: number, b: number) {
//   if (b == 0) {
//     return a
//   }
//
//   return gcd(b, a % b)
// }
//
// export { gcd }

// import './array'
//
// import io from './io'
// import { gcd } from './numberTheory'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let m = a.max()
//
//   let r = -1
//
//   for (let x of a) {
//     if (x == m) {
//       continue
//     }
//     if (r == -1) {
//       r = m - x
//       continue
//     }
//     r = gcd(m - x, r)
//   }
//
//   let s = 0
//
//   for (let x of a) {
//     s += (m - x) / r
//   }
//
//   io.puts(s + " " + r)
// }
//
// // io.runEachTest(main)
// io.runMain(main)

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let o=0;o<t;++o){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=n(r(747));let i="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=o.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),o.default.writeFileSync("output.txt",l),console.log(l),o.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{i+=t})),process.stdin.on("end",(e=>{s=i.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function f(){return s[u++]}function h(){return f().split(" ").map((t=>parseFloat(t)))}function c(){return f().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=h();for(;e>0;)t(),e--}))},readline:f,nextNumbers:h,nextBigNumbers:function(){return f().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(h());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=h();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const o=n(r(312)),i=r(719);o.default.runMain((function(){let[t]=o.default.nextNumbers(),e=o.default.nextNumbers(),r=e.max(),n=r;for(let t of e)n=i.gcd(t,n);let s=0;for(let t of e)s+=(r-t)/n;o.default.puts(s+" "+n)}))},719:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.gcd=void 0,e.gcd=function t(e,r){return 0==r?e:t(r,e%r)}},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,r),o.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
// import { gcd } from './numberTheory'
//
// function main() {
//   let [n] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let m = a.max()
//
//   let r = m
//
//   for (let x of a) {
//     r = gcd(x, r)
//   }
//
//   let s = 0
//
//   for (let x of a) {
//     s += (m - x) / r
//   }
//
//   io.puts(s + " " + r)
// }
//
// // io.runEachTest(main)
// io.runMain(main)

'use strict'

const n = parseInt(readline());
let m = readline().split(' ').map(Number);

const gcd = (a,b) => {
    if (a < b) { const c = a; a = b; b = a; }
    while(b) { const c = a % b; a = b; b = c; }
    return a;
};

m = m.sort((a, b) => b - a);
const d = m.slice(1).map(i => m[0] - i).filter(Boolean);
const z = gcd(d[0], d[d.length - 1]);
const y = d.reduce((r, i) => r + i, 0) / z;
write(y + ' ' + z);

'use strict'

const n = parseInt(readline());
let m = readline().split(' ').map(Number);

const gcd = (a,b) => {
    if (a < b) { const c = a; a = b; b = c; }
    while(b) { const c = a % b; a = b; b = c; }
    return a;
};

m = m.sort((a, b) => b - a);
const d = m.slice(1).map(i => m[0] - i).filter(Boolean);
const z = gcd(d[0], d[d.length - 1]);
const y = d.reduce((r, i) => r + i, 0) / z;
write(y + ' ' + z);


var nxo = readline().split(' ').map(Number);
var n = nxo[0];
var x0 = nxo[1];
var x1 = 0;
var x2 = 1100;
for (var i=0; i<n; i++){
	var l = readline().split(' ').map(Number).sort( (a,b) => a-b );
	if (l[0] > x1) x1 = l[0];
	if (l[1] < x2) x2 = l[1];
}
if (x2-x1<0) print(-1);
else if (x0-x1>=0 && x2-x0>=0) print(0);
else {
	print ( Math.min( Math.abs(x0-x1), Math.abs(x0-x2) ) );
}

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]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var segmentNum = integers[0], startPos = integers[1];

	var cover = new Array(1001);
	for (var i = 0; i <= 1000; i += 1) {
		cover[i] = 0;
	}

	for (var i = 0; i < segmentNum; i += 1) {
		var integers = tokenizeIntegers(readline());
		var a = Math.min(integers[0], integers[1]);
		var b = Math.max(integers[0], integers[1]);
		for (var j = a; j <= b; j += 1) {
			cover[j] += 1;
		}
	}

	var best = -1;

	for (var i = startPos; i >= 0; i -= 1) {
		if (cover[i] == segmentNum) {
			best = startPos-i;
			break;
		}
	}

	for (var i = startPos; i <= 1000; i += 1) {
		if (cover[i] == segmentNum && (best === -1 || i-startPos < best)) {
			best = i-startPos;
			break;
		}
	}

	print(best);
}

main();

'use strict'

let lll = readline().split(' ')
const N = lll[0]
const X = lll[1]

var spos = []

while (lll = readline()) spos.push(lll.split(' ').map(v => +v))

spos = spos.map(s => s[0] < s[1] ? s : [s[1], s[0]])

let p = spos.reduce((p, s) => [Math.max(p[0], s[0]), Math.min(p[1], s[1])])

if (p[0] > p[1]) {
  print(-1)
} else {
  if (p[0] <= X && X <= p[1]) {
    print(0)
  } else if (p[0] > X){
    print(p[0] - X)
  } else {
    print(X - p[1])
  }
}

'use strict'

let lll = readline().split(' ')
const N = lll[0]
const X = lll[1]

var spos = []

while (lll = readline()) spos.push(lll.split(' ').map(v => +v))

spos = spos.map(s => s[0] < s[1] ? s : [s[1], s[0]])

let p = spos.reduce((p, s) => [Math.max(p[0], s[0]), Math.min(p[1], s[1])])

if (p[0] > p[1]) {
  print(-1)
} else {
  if (p[0] < X && X < p[1]) {
    print(0)
  } else if (p[0] > X){
    print(p[0] - X)
  } else {
    print(X - p[1])
  }
}


'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n] = ra();
  let s = readline();
  LT({n, s});
  // PROCESSING:
  let D = [new Array(n).fill(0), new Array(n).fill(0)];
  let C = [new Array(n).fill(0), new Array(n).fill(0)];
  let cost = (want, pos)=>+s[pos]==want ? 0 : 1;
  // D[ends with][pos]
  for (let i=1; i<n; i+=2){
    // ends with 1
    let op1 = (D[1][i-2]||0)+cost(1, i-1)+cost(1, i);
    let op0 = (D[0][i-2]||0)+cost(1, i-1)+cost(1, i);
    if (op1<=op0){
      D[1][i] = op1;
      C[1][i] = C[1][i-2]||1;
    } else {
      D[1][i] = op0;
      C[1][i] = (C[0][i-2]||1)+1;
    }
    // ends with 0
    op1 = (D[1][i-2]||0)+cost(0, i-1)+cost(0, i);
    op0 = (D[0][i-2]||0)+cost(0, i-1)+cost(0, i);
    D[0][i] = Math.min(op1, op0);
    if (op1<op0){
      D[0][i] = op1;
      C[0][i] = (C[1][i-2]||1)+1;
    } else {
      D[0][i] = op0;
      C[0][i] = C[0][i-2]||1;
    }
  }
  if (D[1][n-1]==D[0][n-1]){
    if (C[1][n-1]<C[0][n-1]){
      return `${D[1][n-1]} ${C[1][n-1]}`;
    } else {
      return `${D[0][n-1]} ${C[0][n-1]}`;
    }
  }
  if (D[1][n-1]<D[0][n-1]){
    return `${D[1][n-1]} ${C[1][n-1]}`;
  } else {
    return `${D[0][n-1]} ${C[0][n-1]}`;
  }
};

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++) {
        const n = +lines[l++]
        const str = lines[l++]
        output[i] = solve(n, str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str) {
    let ans = 0
    let count = 0
    let p
    for (let i = 0; i < n; i += 2) {
        const a = str[i]
        const b = str[i + 1]
        if (a === b) {
            if (a === p) {
                //
            } else {
                count++
                p = a
            }
        } else {
            //
            ans++
        }
    }
    return ans + ' ' + Math.max(count, 1)
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

/*---------------------------------------------------*/

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

/*---------------------------------------------------*/

const calc = (n, s)=>{
    let result = 0;

    let last = -1;
    let segs = 0;

    for (let i = 0; i < n; i += 2) {
        if (s[i] !== s[i + 1]) result++;
        else {
            if (s[i] !== last) {
                segs++;
                last = s[i];
            }
        }
    }
    if (!segs) segs = 1;

    return `${result} ${segs}`;

    // let segs = [];
    // let length = 1;
    // let cur = s[0];

    // for (let i = 1; i < n; i++) {
    //     if (s[i] !== cur) {
    //         segs.push([length, cur]);
    //         length = 1;
    //         cur = s[i];
    //     } else {
    //         length++;
    //     }
    // }
    // segs.push([length, cur]);
    // console.log(`DEBUG segs`, segs);

    // let m = segs.length;
    // for (let i = 0; i < m; i++) {
    //     let [l, bit] = segs[i];
    //     console.log(`DEBUG i ${i} l ${l} bit`, bit);
    //     if (l % 2 === 0) continue;
    //     let sumSame = 0; let sumDif = 0;
    //     for (let j = i + 1; j < m; j++) {
    //         let [lj, bitj] = segs[j];
    //         console.log(`DEBUG j ${j} lj ${lj} bitj`, bitj);
    //         if (lj % 2 === 0) {
    //             if (bitj === bit) sumSame += lj;
    //             else sumDif += lj;
    //         } else {
    //             if (bitj === bit) {
    //                 result += Math.min(sumDif, sumSame + 2);
    //             } else {
    //                 result += Math.min(sumDif, sumSame) + 1;
    //             }
    //             console.log(`DEBUG result`, result);
    //             i = j;
    //             break;
    //         }
    //     }
    // }

    // return result;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        let n = +readline();
        let s = readline();
        // let a = ra();
        out.push(calc(n, s));
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
var _loop_1 = function (i) {
    var n = +readline();
    var a = readline().split('').map(function (v) { return +v; });
    function f(cur) {
        var count = 0;
        var changes = 1;
        for (var i_1 = 0; i_1 < n / 2; i_1++) {
            if (a[i_1 * 2] !== a[i_1 * 2 + 1]) {
                count += 1;
            }
            else {
                if (cur !== a[i_1 * 2]) {
                    cur = a[i_1 * 2];
                    changes += 1;
                }
            }
        }
        return [count, changes];
    }
    var ans = [f(0), f(1)];
    print(ans[0][1] < ans[1][1] ? "".concat(ans[0][0], " ").concat(ans[0][1]) : "".concat(ans[1][0], " ").concat(ans[1][1]));
};
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var i = _a[_i];
    _loop_1(i);
}

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++) {
        const n = +lines[l++]
        const str = lines[l++]
        output[i] = solve(n, str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str) {
    let s = -1, p
    const ps = []
    for (let i = 0; i < n; i++) {
        const x = str[i]
        if (x !== p) {
            if (s >= 0) {
                ps.push(str.slice(s, i))
            }
            s = i
            p = x
        }
    }
    if (s < n) {
        ps.push(str.slice(s, n))
    }
// console.log(ps)
    let i = 0
    let ans = 0
    let count = 0
    let add = 0
    let zero = 0
    let prev
    while (i < ps.length) {
        const x = ps[i].length + add
        if (x & 1) {
            ans++
            if (x === 1) {
                add = 1
                zero = 1
            } else if (i + 1 < ps.length && ps[i + 1].length <= 2) {
                add = -1
            } else {
                add = 1
            }
        } else {
            add = 0
            if (x === 0) {
                zero = 1
            } else {
                zero = 0
            }
        }
        //
        // console.log(zero, count)
        if (zero) {
            zero = 0
        } else if (ps[i][0] !== prev) {
            count++
            prev = ps[i][0]
        }
        //
        i++
    }
    return ans + ' ' + count
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n] = ra();
  let s = readline();
  LT({n, s});
  // PROCESSING:
  let D = [new Array(n).fill(0), new Array(n).fill(0)];
  let C = [new Array(n).fill(0), new Array(n).fill(0)];
  let cost = (want, pos)=>+s[pos]==want ? 0 : 1;
  // D[ends with][pos]
  for (let i=1; i<n; i+=2){
    // ends with 1
    let op1 = Math.max((D[1][i-2]||0)+cost(1, i-1)+cost(1, i));
    let op0 = Math.max((D[0][i-2]||0)+cost(1, i-1)+cost(1, i));
    if (op1<=op0){
      D[1][i] = op1;
      C[1][i] = C[1][i-2]||1;
    } else {
      D[1][i] = op0;
      C[1][i] = (C[0][i-2]||1)+1;
    }
    // ends with 0
    op1 = Math.max((D[1][i-2]||0)+cost(0, i-1)+cost(0, i));
    op0 = Math.max((D[0][i-2]||0)+cost(0, i-1)+cost(0, i));
    D[0][i] = Math.min(op1, op0);
    if (op1<op0){
      D[0][i] = op1;
      C[0][i] = (C[1][i-2]||1)+1;
    } else {
      D[0][i] = op0;
      C[0][i] = C[0][i-2]||1;
    }
  }
  if (D[1][n-1]<D[0][n-1]){
    return `${D[1][n-1]} ${C[1][n-1]}`;
  } else {
    return `${D[0][n-1]} ${C[0][n-1]}`;
  }
};


'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const ils = ipt.split(EOL).slice(0, -1)
  const [n, m, x] = ils.shift().split(' ').map(v => parseInt(v))
  const X = x * x
  const T = ils.pop()
  ils.pop()
  const K = []
  const L = {}
  const D = {}
  const S = []
  for (let i = 0; i < ils.length; i++) {
    K[i] = ils[i].split('')
  }
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      let l = K[i][j]
      if (l == 'S') S.push([i, j])
      else {
        L[l] = L[l] || []
        L[l].push([i, j])
        D[l] = false
      }
    }
  }
  for (let l in L) {
    let C = L[l]
    for (let j = 0; j < C.length; j++) {
      const [lx, ly] = C[j]

      D[l] = D[l] || S.some(s => Math.pow(s[0] - lx, 2) + Math.pow(s[1] - ly, 2) <= X)
    }
  }

  let count = 0
  let isS = S.length > 0
  for (let i = 0; i < T.length; i++) {
    let l = T[i]
    if (l in L) continue
    l = l.toLowerCase()
    if (l in L && isS) count += !D[l]
    else return console.log(-1)
  }
  console.log(count)
})

var getVals =  function() {return readline().split(' '); };

var getNums = function() {
	return readline().split(' ').map(function(a) {return parseInt(a)});
};

//11-15

var inp = getNums();
var n = inp[0];
var m = inp[1];
var x = inp[2];

var shifts = [];
var keys = {};
var keysArr = [];
var i, j;
var num;

//Get shifts and keysArr
for(i = 0; i < n; i++) {
	var str = readline();
	for (j = 0; j < m; j++) {
		var key = str[j];
		if (key === 'S') {
			shifts.push({x:i, y:j});
		} else {
			keysArr.push({x:i, y:j, k: key})
		}
	}
}

//Get n and string
var finalN = parseInt(readline());
var finalStr = readline();

function getDistance(x1, y1, x2, y2) {
	return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}

//get keys object
keysArr.forEach(function (key) {
	var minS;
	if (shifts.length) {
		minS = getDistance(key.x, key.y, shifts[0].x, shifts[0].y);
		shifts.forEach(function (shift) {
			minS = Math.min(minS, getDistance(key.x, key.y, shift.x, shift.y));
		})
	} else {
		minS = -1;
	}
	if (keys[key.k]) {
		keys[key.k] = Math.min(minS, keys[key.k]);
	} else {
		keys[key.k] = minS;
	}
});

//get function final text
function res() {
	var shiftCount = 0;
	for(var z = 0; z < finalN; z++) {
		var finalK = finalStr[z];
		if (finalK === finalK.toLocaleLowerCase()) {
			if (!keys[finalK]) {
				return -1;
			}
		} else {
			finalK = finalK.toLocaleLowerCase();
			if (!keys[finalK]) {
				return -1;
			} else {
				if (keys[finalK] === -1) {
					return -1;
				} else {
					if (keys[finalK] > x) {
						shiftCount++;
					}
				}
			}
		}
	}
	return shiftCount;
}

print(res());

var getVals =  function() {return readline().split(' '); };

var getNums = function() {
	return readline().split(' ').map(function(a) {return parseInt(a)});
};

//11-15

var inp = getNums();
var n = inp[0];
var m = inp[1];
var x = inp[2];

var shifts = [];
var keys = {};
var keysArr = [];
var i, j;
var num;

//Get shifts and keysArr
for(i = 0; i < n; i++) {
	var str = readline();
	for (j = 0; j < m; j++) {
		var key = str[j];
		if (key === 'S') {
			shifts.push({x:i, y:j});
		} else {
			keysArr.push({x:i, y:j, k: key})
		}
	}
}

//Get n and string
var finalN = parseInt(readline());
var finalStr = readline();

function getDistance(x1, y1, x2, y2) {
	return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}

//get keys object
keysArr.forEach(function (key) {
	var minS;
	if (shifts.length) {
		minS = getDistance(key.x, key.y, shifts[0].x, shifts[0].y);
		shifts.forEach(function (shift) {
			minS = Math.min(minS, getDistance(key.x, key.y, shift.x, shift.y));
		})
	} else {
		minS = -1;
	}
	keys[key.k] = minS;
});

//get function final text
function res() {
	var shiftCount = 0;
	for(var z = 0; z < finalN; z++) {
		var finalK = finalStr[z];
		if (finalK === finalK.toLocaleLowerCase()) {
			if (!keys[finalK]) {
				return -1;
			}
		} else {
			finalK = finalK.toLocaleLowerCase();
			if (!keys[finalK]) {
				return -1;
			} else {
				if (keys[finalK] === -1) {
					return -1;
				} else {
					if (keys[finalK] > x) {
						shiftCount++;
					}
				}
			}
		}
	}
	return shiftCount;
}

print(res());

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const ils = ipt.split(EOL).slice(0, -1)
  const [n, m, x] = ils.shift().split(' ').map(v => parseInt(v))
  const X = x * x
  const T = ils.pop()
  ils.pop()
  const K = []
  const L = {}
  const D = {}
  const S = []
  for (let i = 0; i < ils.length; i++) {
    K[i] = ils[i].split('')
  }
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      let l = K[i][j]
      if (l == 'S') S.push([i, j])
      else {
        L[l] = L[l] || []
        L[l].push([i, j])
        D[l] = false
      }
    }
  }
  for (let l in L) {
    let C = L[l]
    for (let j = 0; j < C.length; j++) {
      const [lx, ly] = C[j]

      D[l] = S.some(s => Math.pow(s[0] - lx, 2) + Math.pow(s[1] - ly, 2) <= X)
    }
  }

  let count = 0
  let isS = S.length > 0
  for (let i = 0; i < T.length; i++) {
    let l = T[i]
    if (l in L) continue
    l = l.toLowerCase()
    if (l in L && isS) count += !D[l]
    else return console.log(-1)
  }
  console.log(count)
})


var t = readline();
for(var  i = 0 ; i < t ; i++){
    var n = readline();
    if(n == 1){
        print(2);
    }
    else if(n % 3 !== 0){
    print(parseInt(n / 3) + 1) ;
    }
    else{
        print((n / 3));
    }
}

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

let currentLine = 0
let inputString = ''

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

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

function readInt() {
  return inputString[currentLine++]
}

function readString() {
  return inputString[currentLine++]
}

function readArrayInt() {
  return inputString[currentLine++].split(' ').map(Number)
}

function readArray() {
  return inputString[currentLine++].split(' ')
}

function solve() {
  const T = readInt()
  for (let i = 0; i < T; ++i) {
    let n = readInt()

      let ans = 0
      if(n % 3 === 0){
          console.log(n / 3)
      } else if (n == 1){
          console.log(2)
      } else if(n == 2){
          console.log(1)
      } else{
          while(n % 3 !== 0){
              n-=2
              ans+=1
          }
          console.log(ans + n / 3)
      }
  }
}

function main() {
  solve()
}

'use strict';

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++];
}

function main() {
    let t=readline()
    while(t-->0){
        let n=parseInt(readline())
        let mod=n%3;
        if(n==1){
            console.log(2)
            continue
        }
        switch(mod){
            case 0:
                console.log(n/3)
                break
            case 1:
            case 2:
                console.log(Math.floor(n/3)+1)
                break
        }
    }
}

'use strict';

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++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        const n = parseInt(readline(), 10);
        const modMap = {
            '0': 0,
            '1': 2,
            '2': 1,
            '3': 1,
            '4': 2,
            '5': 2
        };
        let six = Math.floor(n/6);
        let mod = modMap[n%6];
        let one = ((six * 2) + mod);
        let two = Infinity;
        if (n > 3) {
            let six2 = Math.floor((n-3)/6);
            let mod2 = modMap[(n-3)%6];
            two = ((six2 * 2) + mod2) + 1;
        }
        output(Math.min(one, two));
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var n = lines[i];
        if(n == 1){
            console.log(2);
        }else if(n % 3 === 0){
            console.log(n / 3);
        }else{
            console.log(Math.floor(n / 3) + 1);
        }
    }
});

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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 t = nextInt();
	while(hasNext()){
		var N = nextInt();
		if(N == 1){
			myout(2);
		}else{
			myout(Math.ceil(N / 3));
		}
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        const n = +readLine();
        // const arr = readLine().split(' ').map(p => +p);
        let result = myFunc(n);
        console.log(result);
    }
}

function myFunc(n){
    if(n == 1) return 2;

    if(n % 3 == 0) return n/3;
    else return parseInt(n/3)+1

}

t = readline()
while(t--) {
    n = readline();
    if(n==1) {
        print(2);
        continue;
    }
    else if(n===2 || n===3) {
        print(1);
         continue;
    }
    var ans = n/3;
    if(n%3)ans++;
    print(Math.trunc(ans));

}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var value = parseInt(readline());
    var count = 0;
    if (value % 3 === 0)
    {
        count = value / 3;
    }
    else if (value % 3 === 2)
    {
        value -= 2;
        count++;
        count += (value / 3);
    }
    else
    {
        value -= 2;
        count = 2;
        if (value > 0)
        {
            value -= 2;
            count += (value / 3);
        }
    }
    print(count);
}

var t = +readline()

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

    var n = readline()
    var ans = 0
    if (n == 1) ans = 2
    if (n == 2) ans = 1
    if (n > 2) ans = Math.ceil(n/3)
    print(ans)
}

T=readline()
while(T--){
    n=readline()
    if(n==1) print(2)
    else print(parseInt((n-1)/3)+1)
}

var n;
    var thr, mod;

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        n = parseInt(readline());
        if (n == 1) {
            print(2);
            continue;
        }
        thr = Math.floor(n / 3);
        mod = n % 3;
        var ans;
        if (mod == 2) {
            ans = thr + 1;
        } else if (mod == 0) {
            ans = thr;
        } else {
            ans = thr + 1;
        }
        print(ans);
    }

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

let currentLine = 0
let inputString = ''

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

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

function readInt() {
  return inputString[currentLine++]
}

function readString() {
  return inputString[currentLine++]
}

function readArrayInt() {
  return inputString[currentLine++].split(' ').map(Number)
}

function readArray() {
  return inputString[currentLine++].split(' ')
}

function solve() {
  const T = readInt()
  for (let i = 0; i < T; ++i) {
    let n = readInt()

      let ans = 0
      if(n % 3 === 0){
          console.log(n / 3)
      } else{
          while(n % 3 !== 0){
              n-=2
              ans+=1
          }
          console.log(ans + n / 3)
      }
  }
}

function main() {
  solve()
}

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

let currentLine = 0
let inputString = ''

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

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

function readInt() {
  return inputString[currentLine++]
}

function readString() {
  return inputString[currentLine++]
}

function readArrayInt() {
  return inputString[currentLine++].split(' ').map(Number)
}

function readArray() {
  return inputString[currentLine++].split(' ')
}

function solve() {
  const T = readInt()
  for (let i = 0; i < T; ++i) {
    let n = readInt()

      let ans = 0
      if(n % 3 === 0){
          console.log(n / 3)
      } else{
          while(n % 3 !== 0){
              n-=2
              ans+=1
          }
          console.log(ans)
      }
  }
}

function main() {
  solve()
}

'use strict';

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++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        const n = parseInt(readline(), 10);
        const modMap = {
            '0': 0,
            '1': 2,
            '2': 1,
            '3': 1,
            '4': 2,
            '5': 2
        };
        let six = Math.floor(n/6);
        let mod = modMap[n%6];
        output(((six * 2) + mod));
    }
}

t = readline()
while(t--) {
    n = readline();
    if(n==1) {
        print(2);
        continue;
    }
    else if(n===2 || n===3) {
        print(1);
         continue;
    }
    var ans = n/3;
    if(n%3)ans++;
    print(ans);

}

var t = readline();
for(var  i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 3 === 0){
    print(n / 3);
    }
    else if(n % 3 == 1){
        print(parseInt(n / 3) + 2);
    }
    else if(n % 3 == 2){
        print(parseInt(n / 3) + 1);
    }
}

var t = readline();
for(var  i = 0 ; i < t ; i++){
    var n = readline();
    if(n % 3 === 0){
    print(n / 3);
    }
    else if(n % 2 === 0){
        print(n / 2);
    }
    else if(n % 3 == 1){
        print(parseInt(n / 3) + 2);
    }
    else if(n % 3 == 2){
        print(parseInt(n / 3) + 1);
    }
}