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

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

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

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

d = A("d")
c = B("c")
g = C("g")
m = D("m")
a = C("a")
j = D("j")

d.v = c
c.y = m
g.s = a
g.q = j
m.v = a
m.p = a
m.x = c
m.z = c
a.s = g
a.q = j
j.v = a
j.x = c
j.z = c
j.p = g
assert j.v.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
g = C("g")
m = D("m")
a = C("a")
j = D("j")

d.v = c
c.y = m
g.s = a
g.q = j
m.v = a
m.p = a
m.x = c
m.z = c
a.s = g
a.q = j
j.v = a
j.x = c
j.z = c
j.p = g
assert j.v.s.s.txt == "a"