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

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

d = A("d")
g = B("g")
k = B("k")
h = B("h")
b = A("b")
l = B("l")
i = B("i")

d.u = k
g.z = b
k.z = d
h.z = b
b.u = h
l.z = b
i.z = b
assert d.u.z.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

d = A("d")
g = B("g")
k = B("k")
h = B("h")
b = A("b")
l = B("l")
i = B("i")

d.u = k
g.z = b
k.z = d
h.z = b
b.u = h
l.z = b
i.z = b
assert d.u.z.u.z.txt == "d"