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

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

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

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

g = A("g")
k = B("k")
i = C("i")
h = D("h")
n = B("n")

g.p = i
k.r = n
k.y = h
k.t = h
i.s = g
h.v = i
h.s = k
n.r = k
n.y = h
n.t = h
assert i.s.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

g = A("g")
k = B("k")
i = C("i")
h = D("h")
n = B("n")

g.p = i
k.r = n
k.y = h
k.t = h
i.s = g
h.v = i
h.s = k
n.r = k
n.y = h
n.t = h
assert i.s.p.s.txt == "g"