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

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

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

f = A("f")
e = B("e")
m = C("m")
j = A("j")
h = B("h")
k = C("k")
a = A("a")

f.y = a
e.y = k
e.p = m
m.z = k
m.w = k
j.y = a
h.y = k
h.p = k
k.z = m
k.w = m
a.y = f
assert j.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

f = A("f")
e = B("e")
m = C("m")
j = A("j")
h = B("h")
k = C("k")
a = A("a")

f.y = a
e.y = k
e.p = m
m.z = k
m.w = k
j.y = a
h.y = k
h.p = k
k.z = m
k.w = m
a.y = f
assert j.y.y.y.y.y.y.txt == "f"