class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

h = A("h")
j = B("j")
m = B("m")
n = B("n")
l = A("l")

h.t = l
j.r = l
j.p = m
m.r = h
m.p = n
n.r = h
n.p = m
l.t = h
assert m.r.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

h = A("h")
j = B("j")
m = B("m")
n = B("n")
l = A("l")

h.t = l
j.r = l
j.p = m
m.r = h
m.p = n
n.r = h
n.p = m
l.t = h
assert m.r.t.t.txt == "h"