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

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

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

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

h = A("h")
d = B("d")
k = C("k")
f = D("f")
b = D("b")

h.x = f
d.q = k
d.w = k
k.w = b
k.v = b
f.u = b
f.x = k
f.q = d
f.w = d
b.u = f
b.x = k
b.q = d
b.w = d
assert b.u.w.q.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

h = A("h")
d = B("d")
k = C("k")
f = D("f")
b = D("b")

h.x = f
d.q = k
d.w = k
k.w = b
k.v = b
f.u = b
f.x = k
f.q = d
f.w = d
b.u = f
b.x = k
b.q = d
b.w = d
assert b.u.w.q.w.u.txt == "f"