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

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

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

j = A("j")
h = B("h")
f = C("f")
l = C("l")
e = A("e")
g = B("g")

j.p = e
h.x = f
h.z = e
h.u = g
f.z = g
l.z = g
e.p = j
g.x = l
g.z = j
g.u = h
assert f.z.z.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

j = A("j")
h = B("h")
f = C("f")
l = C("l")
e = A("e")
g = B("g")

j.p = e
h.x = f
h.z = e
h.u = g
f.z = g
l.z = g
e.p = j
g.x = l
g.z = j
g.u = h
assert f.z.z.p.p.p.p.txt == "j"