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

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

d = A("d")
b = B("b")
j = A("j")

d.p = b
b.x = j
b.t = j
j.p = b
assert j.p.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

d = A("d")
b = B("b")
j = A("j")

d.p = b
b.x = j
b.t = j
j.p = b
assert j.p.t.p.txt == "b"