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

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

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

a = A("a")
h = B("h")
g = C("g")
n = B("n")

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

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

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

a = A("a")
h = B("h")
g = C("g")
n = B("n")

a.q = n
h.w = a
g.v = h
n.w = a
assert n.w.q.w.q.txt == "n"