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

a = A("a")
e = B("e")
j = A("j")
b = A("b")

a.p = e
e.r = j
j.p = e
b.p = e
assert a.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

a = A("a")
e = B("e")
j = A("j")
b = A("b")

a.p = e
e.r = j
j.p = e
b.p = e
assert a.p.r.p.txt == "e"