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

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

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

j = A("j")
e = B("e")
i = C("i")
b = A("b")
g = C("g")
m = B("m")
f = A("f")

j.w = e
e.z = f
e.s = j
e.p = m
i.s = g
b.w = m
g.s = i
m.z = f
m.s = b
m.p = e
f.w = e
assert i.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

j = A("j")
e = B("e")
i = C("i")
b = A("b")
g = C("g")
m = B("m")
f = A("f")

j.w = e
e.z = f
e.s = j
e.p = m
i.s = g
b.w = m
g.s = i
m.z = f
m.s = b
m.p = e
f.w = e
assert i.s.s.s.s.txt == "i"