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

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

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

h.p = b
h.s = l
j.q = n
j.w = h
c.q = l
c.w = h
n.p = m
n.s = h
m.q = n
m.w = n
l.p = j
l.s = h
b.q = l
b.w = k
k.p = c
k.s = n
assert n.s.p.q.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: A = None
        self.txt = txt

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

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

h.p = b
h.s = l
j.q = n
j.w = h
c.q = l
c.w = h
n.p = m
n.s = h
m.q = n
m.w = n
l.p = j
l.s = h
b.q = l
b.w = k
k.p = c
k.s = n
assert n.s.p.q.p.w.txt == "h"