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

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

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

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

n = A("n")
b = B("b")
g = C("g")
f = D("f")
d = A("d")

n.v = g
n.u = b
b.u = f
g.q = d
f.w = b
f.o = b
f.v = n
f.t = g
d.v = g
d.u = b
assert f.v.u.u.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.u: B = None
        self.txt = txt

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

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

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

n = A("n")
b = B("b")
g = C("g")
f = D("f")
d = A("d")

n.v = g
n.u = b
b.u = f
g.q = d
f.w = b
f.o = b
f.v = n
f.t = g
d.v = g
d.u = b
assert f.v.u.u.w.txt == "b"