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

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

class C:
    def __init__(self, txt: str):
        self.p: B = None
        self.t: A = None
        self.s: B = None
        self.txt = txt

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

g = A("g")
l = B("l")
a = C("a")
d = D("d")
m = D("m")
k = D("k")

g.v = a
g.x = d
l.s = k
l.x = d
a.p = l
a.s = l
a.t = g
d.p = a
d.q = g
d.r = g
d.x = l
m.p = a
m.q = g
m.r = g
m.x = l
k.p = a
k.q = g
k.r = g
k.x = l
assert l.x.q.v.p.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.x: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: B = None
        self.t: A = None
        self.s: B = None
        self.txt = txt

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

g = A("g")
l = B("l")
a = C("a")
d = D("d")
m = D("m")
k = D("k")

g.v = a
g.x = d
l.s = k
l.x = d
a.p = l
a.s = l
a.t = g
d.p = a
d.q = g
d.r = g
d.x = l
m.p = a
m.q = g
m.r = g
m.x = l
k.p = a
k.q = g
k.r = g
k.x = l
assert l.x.q.v.p.x.p.txt == "a"