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

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

d = A("d")
c = B("c")
m = A("m")
l = B("l")
a = A("a")
k = B("k")
h = B("h")
i = B("i")
g = B("g")

d.r = k
d.z = i
c.v = k
m.r = k
m.z = g
l.v = i
a.r = i
a.z = h
k.v = h
h.v = k
i.v = h
g.v = h
assert a.z.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: B = None
        self.txt = txt

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

d = A("d")
c = B("c")
m = A("m")
l = B("l")
a = A("a")
k = B("k")
h = B("h")
i = B("i")
g = B("g")

d.r = k
d.z = i
c.v = k
m.r = k
m.z = g
l.v = i
a.r = i
a.z = h
k.v = h
h.v = k
i.v = h
g.v = h
assert a.z.v.v.v.txt == "k"