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.s: A = None
        self.txt = txt

m = A("m")
d = B("d")
l = A("l")
k = B("k")
e = B("e")
h = B("h")
c = B("c")
j = A("j")

m.p = c
m.r = j
d.s = l
l.p = h
l.r = j
k.s = j
e.s = l
h.s = j
c.s = l
j.p = c
j.r = l
assert d.s.p.s.r.p.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.s: A = None
        self.txt = txt

m = A("m")
d = B("d")
l = A("l")
k = B("k")
e = B("e")
h = B("h")
c = B("c")
j = A("j")

m.p = c
m.r = j
d.s = l
l.p = h
l.r = j
k.s = j
e.s = l
h.s = j
c.s = l
j.p = c
j.r = l
assert d.s.p.s.r.p.txt == "h"