class A:
    def __init__(self, txt: str):
        self.z: 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")
i = B("i")
l = B("l")
b = A("b")
n = A("n")
m = B("m")
a = B("a")
g = A("g")
h = A("h")
c = A("c")

d.z = i
i.r = a
i.z = a
l.r = a
l.z = a
b.z = l
n.z = m
m.r = a
m.z = a
a.r = m
a.z = i
g.z = m
h.z = a
c.z = l
assert a.z.z.r.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: 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")
i = B("i")
l = B("l")
b = A("b")
n = A("n")
m = B("m")
a = B("a")
g = A("g")
h = A("h")
c = A("c")

d.z = i
i.r = a
i.z = a
l.r = a
l.z = a
b.z = l
n.z = m
m.r = a
m.z = a
a.r = m
a.z = i
g.z = m
h.z = a
c.z = l
assert a.z.z.r.z.z.txt == "i"