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

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

l = A("l")
b = B("b")
j = B("j")
a = B("a")
e = A("e")
g = B("g")
m = B("m")
h = B("h")

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

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

l = A("l")
b = B("b")
j = B("j")
a = B("a")
e = A("e")
g = B("g")
m = B("m")
h = B("h")

l.p = m
b.r = l
j.r = e
a.r = l
e.p = b
g.r = l
m.r = e
h.r = e
assert l.p.r.p.txt == "b"