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

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

h = A("h")
e = B("e")
n = B("n")
k = A("k")

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

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

h = A("h")
e = B("e")
n = B("n")
k = A("k")

h.z = k
h.q = n
e.o = n
n.o = e
k.z = h
k.q = e
assert h.z.q.o.o.txt == "e"