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

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

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

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

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

n.s = e
c.o = n
c.p = n
c.x = g
j.v = k
g.v = i
e.s = n
k.o = e
k.p = n
k.x = i
i.v = g
assert k.p.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

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

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

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

n.s = e
c.o = n
c.p = n
c.x = g
j.v = k
g.v = i
e.s = n
k.o = e
k.p = n
k.x = i
i.v = g
assert k.p.s.s.s.s.txt == "n"