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

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

k = A("k")
a = B("a")
f = A("f")

k.q = a
a.z = k
f.q = a
assert k.q.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

k = A("k")
a = B("a")
f = A("f")

k.q = a
a.z = k
f.q = a
assert k.q.z.q.txt == "a"