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

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

j = A("j")
a = B("a")
f = B("f")

j.o = a
a.p = j
f.p = j
assert j.o.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
f = B("f")

j.o = a
a.p = j
f.p = j
assert j.o.p.o.txt == "a"