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

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

f = A("f")
j = B("j")
l = B("l")
b = A("b")

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

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

f = A("f")
j = B("j")
l = B("l")
b = A("b")

f.z = b
j.p = l
j.q = b
l.p = j
l.q = f
b.z = f
assert l.p.p.p.txt == "j"