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

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

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

f = A("f")
g = B("g")
j = C("j")
a = A("a")

f.v = a
f.u = a
f.p = g
g.u = j
g.p = j
g.y = f
j.r = f
a.v = f
a.u = f
a.p = g
assert f.p.u.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.p: B = None
        self.u: A = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
j = C("j")
a = A("a")

f.v = a
f.u = a
f.p = g
g.u = j
g.p = j
g.y = f
j.r = f
a.v = f
a.u = f
a.p = g
assert f.p.u.r.v.txt == "a"