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

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

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

a = A("a")
g = B("g")
l = C("l")
c = C("c")
d = A("d")
k = A("k")

a.y = d
g.q = l
l.p = c
l.v = g
c.p = l
c.v = g
d.y = a
k.y = d
assert d.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

a = A("a")
g = B("g")
l = C("l")
c = C("c")
d = A("d")
k = A("k")

a.y = d
g.q = l
l.p = c
l.v = g
c.p = l
c.v = g
d.y = a
k.y = d
assert d.y.y.y.y.y.y.txt == "d"