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

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

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

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

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

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

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

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

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

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

d.v = f
d.s = a
d.q = a
f.q = n
n.w = d
a.u = f
assert f.q.w.v.txt == "f"