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

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

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

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

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

c.y = n
h.z = n
h.u = c
n.v = h
n.u = d
n.q = i
d.q = g
g.v = h
g.u = d
g.q = a
i.v = h
i.u = d
i.q = a
a.v = h
a.u = d
a.q = i
assert c.y.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

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

c.y = n
h.z = n
h.u = c
n.v = h
n.u = d
n.q = i
d.q = g
g.v = h
g.u = d
g.q = a
i.v = h
i.u = d
i.q = a
a.v = h
a.u = d
a.q = i
assert c.y.v.u.txt == "c"