def METHOD_NAME(orig, rollup=None):
    if type(orig) is list:
        return orig
    if rollup:
        if orig.get("@type") == "And":
            if not orig.get("and") or not len(orig["and"]):
                return {}
            if len(orig["and"]) == 1:
                return METHOD_NAME(orig["and"][0], rollup)
        if orig.get("@type") == "Or":
            if not orig.get("or") or not len(orig["or"]):
                return {}
            if len(orig["or"]) == 1:
                return METHOD_NAME(orig["or"][0], rollup)
        if "query" in orig and orig["@type"] != "Comment":
            if type(orig["query"]) is tuple:
                orig["query"] = orig["query"][0].to_dict()
            if not orig["query"].get("@type"):
                return {}
        if "consequent" in orig:
            if not orig["consequent"].get("@type"):
                return {}
    nuj = {}
    for key, part in orig.items():
        if type(part) is list:
            nupart = []
            for item in part:
                if type(item) is dict:
                    sub = METHOD_NAME(item, rollup)
                    if sub:
                        nupart.append(sub)
                else:
                    nupart.append(item)
            nuj[key] = nupart
        elif type(part) is dict:
            query = METHOD_NAME(part, rollup)
            if query:
                nuj[key] = query
        else:
            nuj[key] = part
    return nuj