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

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

i = A("i")
k = B("k")
h = A("h")

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

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

i = A("i")
k = B("k")
h = A("h")

i.z = k
i.q = h
k.r = i
h.z = k
h.q = i
assert h.z.r.q.txt == "h"