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

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

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

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

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

g.v = a
n.z = c
n.w = c
n.q = d
n.u = a
c.x = n
c.z = n
c.r = g
a.u = d
a.p = d
a.q = d
a.v = g
d.u = a
d.p = a
d.q = a
d.v = g
l.v = a
assert a.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

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

g.v = a
n.z = c
n.w = c
n.q = d
n.u = a
c.x = n
c.z = n
c.r = g
a.u = d
a.p = d
a.q = d
a.v = g
d.u = a
d.p = a
d.q = a
d.v = g
l.v = a
assert a.v.v.v.v.txt == "a"