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

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

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

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

n.r = a
g.s = f
g.t = a
a.u = n
f.u = n
assert g.t.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

n.r = a
g.s = f
g.t = a
a.u = n
f.u = n
assert g.t.u.r.u.txt == "n"