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

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

e = A("e")
h = B("h")
m = B("m")
g = B("g")
k = A("k")
j = B("j")
i = A("i")

e.p = g
e.r = k
h.r = i
h.q = j
m.r = e
m.q = h
g.r = k
g.q = j
k.p = j
k.r = i
j.r = i
j.q = m
i.p = h
i.r = k
assert k.p.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: A = None
        self.txt = txt

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

e = A("e")
h = B("h")
m = B("m")
g = B("g")
k = A("k")
j = B("j")
i = A("i")

e.p = g
e.r = k
h.r = i
h.q = j
m.r = e
m.q = h
g.r = k
g.q = j
k.p = j
k.r = i
j.r = i
j.q = m
i.p = h
i.r = k
assert k.p.q.q.txt == "h"