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

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

n = A("n")
a = B("a")
e = A("e")
h = A("h")
b = B("b")
l = B("l")
c = B("c")
k = A("k")

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

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

n = A("n")
a = B("a")
e = A("e")
h = A("h")
b = B("b")
l = B("l")
c = B("c")
k = A("k")

n.q = b
n.r = h
a.p = h
a.w = n
e.q = l
e.r = k
h.q = l
h.r = e
b.p = h
b.w = h
l.p = k
l.w = k
c.p = h
c.w = e
k.q = c
k.r = e
assert l.p.q.p.txt == "h"