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

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

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

h = A("h")
i = B("i")
n = C("n")
j = C("j")
f = B("f")
g = A("g")

h.z = j
h.w = n
h.r = g
i.r = h
i.t = h
i.s = g
n.y = f
n.q = j
j.y = f
j.q = n
f.r = g
f.s = g
f.t = h
g.z = n
g.w = j
g.r = h
assert n.y.s.w.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.w: C = None
        self.r: A = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
n = C("n")
j = C("j")
f = B("f")
g = A("g")

h.z = j
h.w = n
h.r = g
i.r = h
i.t = h
i.s = g
n.y = f
n.q = j
j.y = f
j.q = n
f.r = g
f.s = g
f.t = h
g.z = n
g.w = j
g.r = h
assert n.y.s.w.txt == "j"