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

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

j = A("j")
i = B("i")
k = B("k")

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

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

j = A("j")
i = B("i")
k = B("k")

j.p = i
j.o = k
i.p = j
k.p = j
assert i.p.p.p.txt == "j"