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

class B:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.u: D = None
        self.q: D = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
m = C("m")
g = D("g")
h = E("h")

n.w = d
d.y = g
d.u = n
m.u = g
m.q = g
g.u = d
h.r = m
h.q = d
assert m.q.u.y.u.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: D = None
        self.u: A = None
        self.txt = txt

class C:
    def __init__(self, txt: str):
        self.u: D = None
        self.q: D = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
m = C("m")
g = D("g")
h = E("h")

n.w = d
d.y = g
d.u = n
m.u = g
m.q = g
g.u = d
h.r = m
h.q = d
assert m.q.u.y.u.y.txt == "g"