class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: C = 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.s: A = None
        self.txt = txt

a = A("a")
l = B("l")
g = C("g")

a.u = l
a.p = g
l.p = g
g.s = a
assert l.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.p: C = 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.s: A = None
        self.txt = txt

a = A("a")
l = B("l")
g = C("g")

a.u = l
a.p = g
l.p = g
g.s = a
assert l.p.s.p.txt == "g"