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

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

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

h = A("h")
a = B("a")
m = C("m")
j = C("j")
k = B("k")
c = B("c")
n = C("n")
b = B("b")
d = A("d")
g = C("g")

h.w = d
a.v = j
a.q = j
m.r = n
m.p = c
j.r = m
j.p = c
k.v = m
k.q = g
c.v = n
c.q = m
n.r = g
n.p = k
b.v = n
b.q = n
d.w = h
g.r = j
g.p = k
assert j.p.q.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
m = C("m")
j = C("j")
k = B("k")
c = B("c")
n = C("n")
b = B("b")
d = A("d")
g = C("g")

h.w = d
a.v = j
a.q = j
m.r = n
m.p = c
j.r = m
j.p = c
k.v = m
k.q = g
c.v = n
c.q = m
n.r = g
n.p = k
b.v = n
b.q = n
d.w = h
g.r = j
g.p = k
assert j.p.q.r.r.r.r.r.txt == "n"