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

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

k = A("k")
h = B("h")
f = B("f")
g = A("g")
d = B("d")
b = A("b")

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

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

k = A("k")
h = B("h")
f = B("f")
g = A("g")
d = B("d")
b = A("b")

k.w = h
k.u = d
h.z = d
h.r = f
f.z = d
f.r = h
g.w = f
g.u = h
d.z = h
d.r = h
b.w = f
b.u = d
assert h.r.r.z.z.z.txt == "d"