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

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

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

d = A("d")
a = B("a")
b = C("b")
n = A("n")
k = A("k")
h = A("h")

d.u = b
a.v = h
b.q = a
n.u = b
k.u = b
h.u = b
assert k.u.q.v.u.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

d = A("d")
a = B("a")
b = C("b")
n = A("n")
k = A("k")
h = A("h")

d.u = b
a.v = h
b.q = a
n.u = b
k.u = b
h.u = b
assert k.u.q.v.u.q.v.txt == "h"