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

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

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

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

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

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

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

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

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

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

k.s = a
n.w = k
g.p = l
a.x = k
a.u = n
l.p = g
assert g.p.p.p.p.txt == "g"