// Danny Wasserman
// 7/10/2014
// Solution to SI@UCF Week #1 Algorithms Contest Problem: Drop

import java.util.Scanner;

public class drop {
  public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    int cases = in.nextInt();

    // Process cases.
    for (int co = 1; co <= cases; co++) {

      // Read in grid.
      int h = in.nextInt();
      int w = in.nextInt();
      char[][] g = new char[h][w];
      for (int i = 0; i < h; i++)
        g[i] = in.next().toCharArray();

      // Count X's in each column.
      int[] freq = new int[w];
      for (int i = 0; i < w; i++) {
        int cnt = 0;
        for (int j = 0; j < h; j++)
          if (g[j][i] == 'X') cnt++;
        freq[i] = cnt;
      }

      // Sweep through data looking for the largest positive change and print.
      int drop = 0;
      for (int i = 0; i < w - 1; i++)
        drop = Math.max(drop, freq[i + 1] - freq[i]);
      System.out.println(drop);
    }
  }
}
