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

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

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

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

m = A("m")
l = B("l")
i = C("i")
g = D("g")
d = B("d")
f = C("f")

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

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

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

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

m = A("m")
l = B("l")
i = C("i")
g = D("g")
d = B("d")
f = C("f")

m.s = f
m.p = g
l.v = m
l.t = g
i.x = d
i.t = m
i.q = m
i.v = f
g.v = i
d.v = m
d.t = g
f.x = d
f.t = m
f.q = m
f.v = i
assert g.v.q.p.v.txt == "i"