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

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

i = A("i")
m = B("m")
c = A("c")
k = B("k")

i.x = c
i.s = k
m.z = c
c.x = i
c.s = k
k.z = c
assert k.z.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: B = None
        self.txt = txt

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

i = A("i")
m = B("m")
c = A("c")
k = B("k")

i.x = c
i.s = k
m.z = c
c.x = i
c.s = k
k.z = c
assert k.z.s.z.s.txt == "k"