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

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

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

j = A("j")
a = B("a")
b = C("b")
k = A("k")
n = B("n")
g = C("g")

j.p = k
a.z = n
a.y = b
b.q = g
k.p = j
n.z = a
n.y = g
g.q = b
assert g.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

j = A("j")
a = B("a")
b = C("b")
k = A("k")
n = B("n")
g = C("g")

j.p = k
a.z = n
a.y = b
b.q = g
k.p = j
n.z = a
n.y = g
g.q = b
assert g.q.q.q.q.q.txt == "b"