Solve the island counting problem on a grid using connected-component traversal.
Implement num_islands(grid), where grid is a rectangular list of lists containing only the strings "1" and "0". Return the number of connected components of "1" cells, considering only up, down, left, and right neighbors. The function may use an iterative traversal and may modify the input grid.
def num_islands(grid):