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

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

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

f = A("f")
k = B("k")
g = C("g")
l = B("l")
b = B("b")
m = C("m")
a = A("a")
i = A("i")
h = B("h")

f.p = h
f.y = i
f.v = g
k.v = a
k.q = g
g.p = h
g.u = b
l.v = a
l.q = m
b.v = a
b.q = g
m.p = k
m.u = k
a.p = k
a.y = i
a.v = m
i.p = k
i.y = f
i.v = m
h.v = f
h.q = m
assert k.v.p.q.p.q.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: A = None
        self.v: C = None
        self.txt = txt

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

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

f = A("f")
k = B("k")
g = C("g")
l = B("l")
b = B("b")
m = C("m")
a = A("a")
i = A("i")
h = B("h")

f.p = h
f.y = i
f.v = g
k.v = a
k.q = g
g.p = h
g.u = b
l.v = a
l.q = m
b.v = a
b.q = g
m.p = k
m.u = k
a.p = k
a.y = i
a.v = m
i.p = k
i.y = f
i.v = m
h.v = f
h.q = m
assert k.v.p.q.p.q.u.txt == "k"