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

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

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

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

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

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

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