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

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

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

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

c = A("c")
b = B("b")
m = C("m")
g = D("g")

c.s = m
b.y = c
b.p = c
b.x = c
b.v = m
m.u = c
m.r = c
g.w = c
assert m.u.s.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
m = C("m")
g = D("g")

c.s = m
b.y = c
b.p = c
b.x = c
b.v = m
m.u = c
m.r = c
g.w = c
assert m.u.s.u.txt == "c"