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

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

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

g = A("g")
k = B("k")
a = C("a")
d = B("d")
i = A("i")
b = C("b")

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

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

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

g = A("g")
k = B("k")
a = C("a")
d = B("d")
i = A("i")
b = C("b")

g.y = i
g.v = i
k.p = d
a.q = b
d.p = k
i.y = g
i.v = g
b.q = a
assert b.q.q.q.q.q.q.txt == "b"