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

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

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

m = A("m")
e = B("e")
b = C("b")
d = C("d")
l = C("l")
a = A("a")
g = A("g")
j = A("j")
i = B("i")
f = B("f")

m.s = l
m.v = g
e.q = i
e.p = i
e.r = d
b.q = e
d.q = i
l.q = f
a.s = l
a.v = m
g.s = l
g.v = m
j.s = l
j.v = a
i.q = f
i.r = l
i.p = e
f.q = e
f.r = d
f.p = i
assert a.v.s.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.v: A = None
        self.txt = txt

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

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

m = A("m")
e = B("e")
b = C("b")
d = C("d")
l = C("l")
a = A("a")
g = A("g")
j = A("j")
i = B("i")
f = B("f")

m.s = l
m.v = g
e.q = i
e.p = i
e.r = d
b.q = e
d.q = i
l.q = f
a.s = l
a.v = m
g.s = l
g.v = m
j.s = l
j.v = a
i.q = f
i.r = l
i.p = e
f.q = e
f.r = d
f.p = i
assert a.v.s.q.p.txt == "i"