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

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

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

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

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

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

f.y = n
f.t = n
b.o = d
d.o = b
n.y = f
n.t = f
assert b.o.o.o.txt == "d"