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

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

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

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

g = A("g")
b = B("b")
m = C("m")
n = D("n")
e = C("e")
d = D("d")
i = B("i")

g.p = d
b.q = g
b.x = i
b.r = n
m.x = d
m.z = b
m.u = e
m.w = g
n.w = b
e.x = d
e.z = b
e.u = m
e.w = g
d.w = b
i.q = g
i.x = b
i.r = n
assert d.w.x.r.w.r.w.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

g = A("g")
b = B("b")
m = C("m")
n = D("n")
e = C("e")
d = D("d")
i = B("i")

g.p = d
b.q = g
b.x = i
b.r = n
m.x = d
m.z = b
m.u = e
m.w = g
n.w = b
e.x = d
e.z = b
e.u = m
e.w = g
d.w = b
i.q = g
i.x = b
i.r = n
assert d.w.x.r.w.r.w.q.txt == "g"