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

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

a = A("a")
g = B("g")
k = A("k")
b = B("b")

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

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

a = A("a")
g = B("g")
k = A("k")
b = B("b")

a.z = k
g.q = k
k.z = a
b.q = k
assert g.q.z.z.txt == "k"