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

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

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

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

d = A("d")
g = B("g")
c = C("c")
e = D("e")
k = D("k")
f = B("f")

d.v = e
d.p = f
d.r = f
d.x = c
g.z = k
g.v = f
g.r = d
c.v = d
c.o = d
e.u = d
e.q = k
e.p = c
k.u = d
k.q = e
k.p = c
f.z = k
f.v = g
f.r = d
assert d.v.q.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.p: B = None
        self.r: B = None
        self.x: C = None
        self.txt = txt

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

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

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

d = A("d")
g = B("g")
c = C("c")
e = D("e")
k = D("k")
f = B("f")

d.v = e
d.p = f
d.r = f
d.x = c
g.z = k
g.v = f
g.r = d
c.v = d
c.o = d
e.u = d
e.q = k
e.p = c
k.u = d
k.q = e
k.p = c
f.z = k
f.v = g
f.r = d
assert d.v.q.p.o.txt == "d"