class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

f = A("f")
d = B("d")
n = A("n")

f.y = n
d.y = n
n.y = f
assert n.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

f = A("f")
d = B("d")
n = A("n")

f.y = n
d.y = n
n.y = f
assert n.y.y.y.txt == "f"