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

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

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

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

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

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

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

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

n.q = j
d.w = j
d.q = g
g.v = c
g.q = n
c.q = a
f.w = d
f.q = g
j.w = d
j.q = g
a.w = j
a.q = g
assert f.w.q.v.q.q.v.txt == "c"