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

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

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

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

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

m.s = g
m.v = g
i.u = m
g.p = m
g.r = m
j.v = m
a.u = m
assert j.v.s.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.v: C = None
        self.txt = txt

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

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

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

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

m.s = g
m.v = g
i.u = m
g.p = m
g.r = m
j.v = m
a.u = m
assert j.v.s.p.s.p.txt == "m"