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

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

m = A("m")
h = B("h")
e = A("e")
i = A("i")
a = B("a")
l = B("l")
f = A("f")
c = A("c")
j = B("j")

m.q = i
m.z = h
h.r = i
e.q = i
e.z = l
i.q = m
i.z = j
a.r = f
l.r = f
f.q = i
f.z = j
c.q = e
c.z = j
j.r = f
assert h.r.z.r.z.r.q.z.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: B = None
        self.txt = txt

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

m = A("m")
h = B("h")
e = A("e")
i = A("i")
a = B("a")
l = B("l")
f = A("f")
c = A("c")
j = B("j")

m.q = i
m.z = h
h.r = i
e.q = i
e.z = l
i.q = m
i.z = j
a.r = f
l.r = f
f.q = i
f.z = j
c.q = e
c.z = j
j.r = f
assert h.r.z.r.z.r.q.z.r.q.txt == "i"