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

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

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

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

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

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

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