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

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

class C:
    def __init__(self, txt: str):
        self.t: A = None
        self.u: A = None
        self.txt = txt

i = A("i")
f = B("f")
m = C("m")
g = C("g")
c = A("c")
n = A("n")
h = B("h")
e = B("e")

i.z = m
i.s = e
f.x = e
f.r = h
f.p = n
m.t = i
m.u = i
g.t = i
g.u = n
c.z = m
c.s = f
n.z = m
n.s = f
h.x = e
h.r = f
h.p = n
e.x = f
e.r = h
e.p = n
assert f.x.r.r.r.x.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.s: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.t: A = None
        self.u: A = None
        self.txt = txt

i = A("i")
f = B("f")
m = C("m")
g = C("g")
c = A("c")
n = A("n")
h = B("h")
e = B("e")

i.z = m
i.s = e
f.x = e
f.r = h
f.p = n
m.t = i
m.u = i
g.t = i
g.u = n
c.z = m
c.s = f
n.z = m
n.s = f
h.x = e
h.r = f
h.p = n
e.x = f
e.r = h
e.p = n
assert f.x.r.r.r.x.r.r.txt == "f"