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

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

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

g = A("g")
a = B("a")
e = C("e")
c = C("c")
n = A("n")
h = B("h")
j = C("j")

g.w = n
g.y = a
a.y = g
a.w = h
a.x = n
e.w = c
c.w = j
n.w = g
n.y = h
h.y = g
h.w = a
h.x = n
j.w = c
assert j.w.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.y: B = None
        self.txt = txt

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

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

g = A("g")
a = B("a")
e = C("e")
c = C("c")
n = A("n")
h = B("h")
j = C("j")

g.w = n
g.y = a
a.y = g
a.w = h
a.x = n
e.w = c
c.w = j
n.w = g
n.y = h
h.y = g
h.w = a
h.x = n
j.w = c
assert j.w.w.w.w.w.w.w.txt == "c"