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

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

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

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

g = A("g")
n = B("n")
a = C("a")
k = D("k")

g.w = n
n.t = a
a.x = k
a.r = n
a.u = g
k.s = a
k.u = a
assert g.w.t.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

g = A("g")
n = B("n")
a = C("a")
k = D("k")

g.w = n
n.t = a
a.x = k
a.r = n
a.u = g
k.s = a
k.u = a
assert g.w.t.x.u.txt == "a"