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

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

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

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

g = A("g")
c = B("c")
a = C("a")
k = D("k")
j = A("j")

g.s = k
g.y = k
c.u = a
a.p = c
k.y = g
k.u = g
k.t = a
k.v = j
j.s = k
j.y = k
assert k.v.s.y.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.y: D = None
        self.txt = txt

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

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

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

g = A("g")
c = B("c")
a = C("a")
k = D("k")
j = A("j")

g.s = k
g.y = k
c.u = a
a.p = c
k.y = g
k.u = g
k.t = a
k.v = j
j.s = k
j.y = k
assert k.v.s.y.s.txt == "k"