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

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

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

n = A("n")
g = B("g")
h = C("h")
e = B("e")
d = B("d")

n.s = h
n.w = h
g.q = h
g.v = e
g.z = e
h.r = g
h.w = n
e.q = h
e.v = g
e.z = d
d.q = h
d.v = g
d.z = e
assert n.s.r.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.w: C = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
h = C("h")
e = B("e")
d = B("d")

n.s = h
n.w = h
g.q = h
g.v = e
g.z = e
h.r = g
h.w = n
e.q = h
e.v = g
e.z = d
d.q = h
d.v = g
d.z = e
assert n.s.r.q.w.txt == "n"