from typing import List
from typing import Tuple


def coords_to_query_string(coords:List[Tuple[float, float]], api_key:str) -> str:
    """
    Converts a list of lat,lon tuples into the query format required
    by Google Maps Elevation API.

    Args:
        coords: List of (lat,lon) tuples.
        api_key: Api key for Google Elevation API

    Returns:
        Query string.

    """
    prefix = "json?path=" if len(coords) > 1 else "json?locations="
    path_string = ""
    for lat, lon in coords:
        path_string += f"{str(lat)},{str(lon)}|"
    path_string = path_string[:-1]

    sample_string = f"&samples={len(coords)}" if len(coords) > 1 else ""
    key_string = f"&key={api_key}"

    return prefix + path_string + sample_string + key_string