def check_via_group(via_group, source_sink):
    """
    Check the validity of each via set in the via group.
    :param via_group: the via_group in question.
    :return: via_group with all valid candidate(s)
    """
    # valid for 2-via cell: 1 source, 1 sink
    # valid for 3-via cell: 2 sink, 1 source
    valid_group = []
    for each_group in via_group:
        num_vias = len(each_group)
        num_source = 0
        num_sink = 0
        for each_via in each_group:
            # 0 = sink, 1 = source
            if source_sink[each_via[2]] == 1:
                num_source += 1
            elif source_sink[each_via[2]] == 0:
                num_sink += 1
        if num_source <= 1 and num_sink <=2:
            valid_group.append(each_group)
    return valid_group