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

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

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

k = A("k")
h = B("h")
f = C("f")
e = A("e")
g = C("g")

k.u = e
k.v = e
k.y = h
h.p = g
f.p = g
f.w = g
f.v = h
e.u = k
e.v = k
e.y = h
g.p = f
g.w = f
g.v = h
assert g.v.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.y: B = None
        self.v: A = None
        self.txt = txt

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

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

k = A("k")
h = B("h")
f = C("f")
e = A("e")
g = C("g")

k.u = e
k.v = e
k.y = h
h.p = g
f.p = g
f.w = g
f.v = h
e.u = k
e.v = k
e.y = h
g.p = f
g.w = f
g.v = h
assert g.v.p.p.txt == "f"