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

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

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

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

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

k.t = a
k.p = j
k.r = g
a.p = k
a.r = n
a.s = d
a.t = j
g.p = k
g.t = k
g.x = k
j.s = k
n.s = k
d.p = k
d.r = j
d.t = j
d.s = a
assert a.s.s.t.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: D = None
        self.r: C = None
        self.txt = txt

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

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

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

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

k.t = a
k.p = j
k.r = g
a.p = k
a.r = n
a.s = d
a.t = j
g.p = k
g.t = k
g.x = k
j.s = k
n.s = k
d.p = k
d.r = j
d.t = j
d.s = a
assert a.s.s.t.s.r.txt == "g"