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

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

e = A("e")
k = B("k")
d = A("d")
m = A("m")
g = B("g")
n = A("n")
c = B("c")

e.z = d
k.s = c
d.z = m
m.z = e
g.s = k
n.z = d
c.s = g
assert m.z.z.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.s: B = None
        self.txt = txt

e = A("e")
k = B("k")
d = A("d")
m = A("m")
g = B("g")
n = A("n")
c = B("c")

e.z = d
k.s = c
d.z = m
m.z = e
g.s = k
n.z = d
c.s = g
assert m.z.z.z.z.txt == "e"