from typing import List


def head_commit_query(user: str, repo: str, branches: List[str]) -> str:
    """
    Fetch the head commit for a list of branches
    """

    def branch_part(branch: str, num: int) -> str:
        return f"""
        r{num}: repository(name: "{repo}", owner: "{user}") {{
            ref(qualifiedName:"refs/heads/{branch}") {{
            name
            target {{
                ... on Commit {{
                    oid
                }}        
            }}
        }}
        }}
        """

    parts = [branch_part(branch, i) for i, branch in enumerate(branches)]
    return "{" + "\n".join(parts) + "}"