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

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

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

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

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

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

e.p = f
k.q = e
j.q = f
f.p = e
assert e.p.p.p.txt == "f"