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.r: B = None
        self.z: B = None
        self.txt = txt

d = A("d")
g = B("g")
l = A("l")
h = B("h")

d.z = g
d.u = h
g.r = h
g.z = h
l.z = h
l.u = g
h.r = g
h.z = g
assert l.u.r.r.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.r: B = None
        self.z: B = None
        self.txt = txt

d = A("d")
g = B("g")
l = A("l")
h = B("h")

d.z = g
d.u = h
g.r = h
g.z = h
l.z = h
l.u = g
h.r = g
h.z = g
assert l.u.r.r.txt == "g"