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

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

h = A("h")
m = B("m")
c = A("c")
k = B("k")
j = B("j")
f = A("f")
g = B("g")
b = B("b")
d = A("d")
a = B("a")

h.z = k
m.y = g
m.z = k
c.z = a
k.y = b
k.z = b
j.y = k
j.z = m
f.z = k
g.y = b
g.z = k
b.y = m
b.z = m
d.z = k
a.y = j
a.z = j
assert k.y.y.y.z.y.z.z.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

h = A("h")
m = B("m")
c = A("c")
k = B("k")
j = B("j")
f = A("f")
g = B("g")
b = B("b")
d = A("d")
a = B("a")

h.z = k
m.y = g
m.z = k
c.z = a
k.y = b
k.z = b
j.y = k
j.z = m
f.z = k
g.y = b
g.z = k
b.y = m
b.z = m
d.z = k
a.y = j
a.z = j
assert k.y.y.y.z.y.z.z.z.y.txt == "m"