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

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

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

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

c = A("c")
n = B("n")
g = C("g")
a = D("a")
i = A("i")
d = C("d")

c.w = d
n.q = a
n.z = a
n.r = a
n.o = i
g.y = d
g.s = i
a.s = c
i.w = d
d.y = g
d.s = i
assert n.z.s.w.s.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

c = A("c")
n = B("n")
g = C("g")
a = D("a")
i = A("i")
d = C("d")

c.w = d
n.q = a
n.z = a
n.r = a
n.o = i
g.y = d
g.s = i
a.s = c
i.w = d
d.y = g
d.s = i
assert n.z.s.w.s.w.y.txt == "g"