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

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

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

j = A("j")
d = B("d")
i = C("i")
c = A("c")
n = B("n")
h = A("h")
a = A("a")
f = C("f")

j.s = f
j.q = c
d.q = c
d.p = f
d.v = j
i.z = n
i.s = f
i.p = a
c.s = i
c.q = h
n.q = c
n.v = c
n.p = i
h.s = i
h.q = c
a.s = i
a.q = h
f.z = d
f.s = i
f.p = h
assert f.s.p.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.q: A = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
i = C("i")
c = A("c")
n = B("n")
h = A("h")
a = A("a")
f = C("f")

j.s = f
j.q = c
d.q = c
d.p = f
d.v = j
i.z = n
i.s = f
i.p = a
c.s = i
c.q = h
n.q = c
n.v = c
n.p = i
h.s = i
h.q = c
a.s = i
a.q = h
f.z = d
f.s = i
f.p = h
assert f.s.p.q.s.txt == "i"