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

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

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

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

n = A("n")
a = B("a")
f = C("f")
d = D("d")

n.x = a
n.o = a
n.y = a
n.v = d
a.r = f
a.v = f
a.x = d
f.w = a
f.u = a
d.q = a
d.w = a
d.u = n
assert d.u.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: B = None
        self.v: D = None
        self.y: B = None
        self.txt = txt

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

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

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

n = A("n")
a = B("a")
f = C("f")
d = D("d")

n.x = a
n.o = a
n.y = a
n.v = d
a.r = f
a.v = f
a.x = d
f.w = a
f.u = a
d.q = a
d.w = a
d.u = n
assert d.u.x.x.txt == "d"