class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: A = 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.v: A = None
        self.t: A = None
        self.txt = txt

n = A("n")
m = B("m")
g = C("g")
i = C("i")
l = B("l")
k = C("k")
d = A("d")

n.v = d
n.q = d
m.v = i
g.v = n
g.t = n
i.v = n
i.t = d
l.v = g
k.v = n
k.t = n
d.v = n
d.q = n
assert m.v.t.q.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.q: A = 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.v: A = None
        self.t: A = None
        self.txt = txt

n = A("n")
m = B("m")
g = C("g")
i = C("i")
l = B("l")
k = C("k")
d = A("d")

n.v = d
n.q = d
m.v = i
g.v = n
g.t = n
i.v = n
i.t = d
l.v = g
k.v = n
k.t = n
d.v = n
d.q = n
assert m.v.t.q.v.q.v.txt == "d"