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

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

l = A("l")
h = B("h")
m = B("m")
i = A("i")
b = A("b")
g = A("g")
n = A("n")
e = A("e")

l.p = h
l.s = m
h.z = i
h.q = m
m.z = g
m.q = h
i.p = m
i.s = m
b.p = m
b.s = m
g.p = h
g.s = m
n.p = h
n.s = m
e.p = m
e.s = h
assert h.q.q.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
m = B("m")
i = A("i")
b = A("b")
g = A("g")
n = A("n")
e = A("e")

l.p = h
l.s = m
h.z = i
h.q = m
m.z = g
m.q = h
i.p = m
i.s = m
b.p = m
b.s = m
g.p = h
g.s = m
n.p = h
n.s = m
e.p = m
e.s = h
assert h.q.q.z.p.txt == "m"