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

h = A("h")
n = B("n")
g = C("g")
k = A("k")
c = B("c")

h.y = c
n.v = g
g.q = n
g.v = h
k.y = c
c.v = g
assert k.y.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = 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.q: B = None
        self.v: A = None
        self.txt = txt

h = A("h")
n = B("n")
g = C("g")
k = A("k")
c = B("c")

h.y = c
n.v = g
g.q = n
g.v = h
k.y = c
c.v = g
assert k.y.v.q.v.txt == "g"