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

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

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

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

n.x = h
g.s = n
g.w = n
g.u = j
j.z = d
h.x = n
d.s = n
d.u = j
d.w = h
assert d.u.z.s.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

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

n.x = h
g.s = n
g.w = n
g.u = j
j.z = d
h.x = n
d.s = n
d.u = j
d.w = h
assert d.u.z.s.x.x.txt == "n"