from typing import List


def domains_check(domains: List[str]) -> List[str]:
    """
    all input domains should have the same primary, 
    e.g.
     * `example.com`, `a.example.com` are valid
     * `example.com`, `a.example1.com` are invalid
     * `domains=["a.x.com", "b.x.com"]` will be converted to 
     `["x.com", "a.x.com", "b.x.com"]`
    if top-level like `example.com` is not given in `domains`, it will be 
    added here
    """
    if len(domains) == 1:
        return domains
    primary_set: List[str] = []
    for d in domains:
        primary = '.'.join(d.split('.')[-2:])
        primary_set.append(primary)
    if len(set(primary_set)) == 1:
        primary = primary_set.pop()
        # if top-level given by user but not in the first
        if primary in domains:
            # move primary to the first element in domains list
            domains_mod = sorted(domains, key=len)
            return domains_mod
        else:
            # if top-level is not given by user, add it to domains
            return [primary] + domains
    else:
        raise ValueError(f'input domains {domains} have different top-level')