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

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

class C:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: D = None
        self.txt = txt

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

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

a.v = b
a.p = g
a.o = g
a.s = m
m.s = g
m.x = a
m.o = b
g.o = m
g.u = b
b.y = m
assert a.v.y.o.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.p: C = None
        self.o: C = None
        self.s: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: D = None
        self.txt = txt

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

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

a.v = b
a.p = g
a.o = g
a.s = m
m.s = g
m.x = a
m.o = b
g.o = m
g.u = b
b.y = m
assert a.v.y.o.txt == "b"