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

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

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

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

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

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

e.p = f
f.s = e
j.p = f
assert f.s.p.s.txt == "e"