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

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

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

c = A("c")
g = B("g")
a = C("a")
d = C("d")
m = A("m")
f = C("f")
j = B("j")

c.v = j
c.q = a
g.p = c
a.y = c
a.s = c
a.p = g
d.y = m
d.p = j
d.s = c
m.v = g
m.q = d
f.y = c
f.p = j
f.s = m
j.p = c
assert d.s.q.p.p.q.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.q: C = None
        self.txt = txt

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

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

c = A("c")
g = B("g")
a = C("a")
d = C("d")
m = A("m")
f = C("f")
j = B("j")

c.v = j
c.q = a
g.p = c
a.y = c
a.s = c
a.p = g
d.y = m
d.p = j
d.s = c
m.v = g
m.q = d
f.y = c
f.p = j
f.s = m
j.p = c
assert d.s.q.p.p.q.p.p.txt == "c"