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

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

class C:
    def __init__(self, txt: str):
        self.r: D = None
        self.t: D = None
        self.p: D = None
        self.u: B = None
        self.txt = txt

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

d = A("d")
n = B("n")
k = C("k")
j = D("j")
f = D("f")
g = B("g")

d.y = k
d.w = k
n.s = d
n.x = d
n.z = g
k.r = f
k.t = f
k.p = j
k.u = g
j.o = f
j.s = f
j.w = f
f.o = j
f.s = j
f.w = j
g.s = d
g.x = d
g.z = n
assert d.w.p.w.o.w.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.w: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: D = None
        self.t: D = None
        self.p: D = None
        self.u: B = None
        self.txt = txt

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

d = A("d")
n = B("n")
k = C("k")
j = D("j")
f = D("f")
g = B("g")

d.y = k
d.w = k
n.s = d
n.x = d
n.z = g
k.r = f
k.t = f
k.p = j
k.u = g
j.o = f
j.s = f
j.w = f
f.o = j
f.s = j
f.w = j
g.s = d
g.x = d
g.z = n
assert d.w.p.w.o.w.s.txt == "j"