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

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

b = A("b")
d = B("d")
g = A("g")
e = B("e")

b.z = d
b.u = e
d.y = g
d.z = e
g.z = e
g.u = d
e.y = g
e.z = d
assert b.z.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.u: B = None
        self.txt = txt

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

b = A("b")
d = B("d")
g = A("g")
e = B("e")

b.z = d
b.u = e
d.y = g
d.z = e
g.z = e
g.u = d
e.y = g
e.z = d
assert b.z.z.y.txt == "g"