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

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

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

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

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

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

b.u = d
b.t = d
i.y = d
i.t = b
f.y = d
f.t = d
d.u = b
d.t = b
assert d.u.t.u.txt == "b"