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

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

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

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

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

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

e.z = k
e.q = k
n.q = e
n.r = k
k.q = e
k.r = n
assert e.z.r.r.txt == "k"