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

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

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

g = A("g")
i = B("i")
b = C("b")
c = A("c")
k = A("k")
j = B("j")
h = C("h")
l = C("l")

g.y = j
g.q = c
i.y = j
i.q = c
b.z = j
c.y = i
c.q = g
k.y = i
k.q = c
j.y = i
j.q = k
h.z = i
l.z = i
assert g.q.y.q.y.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: A = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
b = C("b")
c = A("c")
k = A("k")
j = B("j")
h = C("h")
l = C("l")

g.y = j
g.q = c
i.y = j
i.q = c
b.z = j
c.y = i
c.q = g
k.y = i
k.q = c
j.y = i
j.q = k
h.z = i
l.z = i
assert g.q.y.q.y.q.y.q.txt == "c"