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

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

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

d = A("d")
c = B("c")
l = C("l")
i = B("i")
f = C("f")
g = C("g")
n = A("n")
a = C("a")
m = C("m")

d.p = c
d.w = n
d.q = i
c.v = m
l.o = m
l.p = d
i.v = a
f.o = g
f.p = d
g.o = f
g.p = d
n.p = c
n.q = c
n.w = d
a.o = g
a.p = n
m.o = g
m.p = d
assert f.p.p.v.o.o.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.w: A = None
        self.q: B = None
        self.txt = txt

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

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

d = A("d")
c = B("c")
l = C("l")
i = B("i")
f = C("f")
g = C("g")
n = A("n")
a = C("a")
m = C("m")

d.p = c
d.w = n
d.q = i
c.v = m
l.o = m
l.p = d
i.v = a
f.o = g
f.p = d
g.o = f
g.p = d
n.p = c
n.q = c
n.w = d
a.o = g
a.p = n
m.o = g
m.p = d
assert f.p.p.v.o.o.p.q.txt == "i"