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

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

l = A("l")
d = B("d")
n = A("n")
b = A("b")
h = A("h")
c = B("c")
m = B("m")
f = B("f")
j = B("j")

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

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

l = A("l")
d = B("d")
n = A("n")
b = A("b")
h = A("h")
c = B("c")
m = B("m")
f = B("f")
j = B("j")

l.z = f
l.q = j
d.r = l
n.z = c
n.q = f
b.z = f
b.q = j
h.z = c
h.q = f
c.r = n
m.r = l
f.r = n
j.r = h
assert h.q.r.q.r.q.r.z.txt == "c"