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

class B:
    def __init__(self, txt: str):
        self.v: 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")
n = B("n")
a = C("a")
f = A("f")
b = B("b")
g = C("g")
j = C("j")

m.x = n
n.v = g
n.p = b
a.q = n
f.x = n
b.v = a
b.p = n
g.q = b
j.q = n
assert j.q.p.p.p.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: 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")
n = B("n")
a = C("a")
f = A("f")
b = B("b")
g = C("g")
j = C("j")

m.x = n
n.v = g
n.p = b
a.q = n
f.x = n
b.v = a
b.p = n
g.q = b
j.q = n
assert j.q.p.p.p.v.q.v.txt == "g"