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

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

n.p = b
d.q = b
j.q = n
f.q = n
b.p = n
assert f.q.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

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

n.p = b
d.q = b
j.q = n
f.q = n
b.p = n
assert f.q.p.p.txt == "n"