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

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

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

e = A("e")
m = B("m")
n = C("n")
k = A("k")
f = B("f")

e.q = k
e.z = k
m.w = f
n.s = m
k.q = e
k.z = e
f.w = m
assert n.s.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.txt = txt

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

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

e = A("e")
m = B("m")
n = C("n")
k = A("k")
f = B("f")

e.q = k
e.z = k
m.w = f
n.s = m
k.q = e
k.z = e
f.w = m
assert n.s.w.w.w.txt == "f"