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

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

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

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

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

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

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

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

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

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

k.y = c
k.s = n
n.p = c
g.y = k
c.t = k
c.v = g
assert k.s.p.v.y.txt == "k"