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

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

g = A("g")
i = B("i")
d = C("d")
a = B("a")
k = C("k")

g.p = a
g.t = a
g.x = a
i.t = g
i.r = g
i.x = g
d.p = a
a.t = g
a.r = g
a.x = g
k.p = i
assert a.r.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.t: B = None
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: A = None
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

g = A("g")
i = B("i")
d = C("d")
a = B("a")
k = C("k")

g.p = a
g.t = a
g.x = a
i.t = g
i.r = g
i.x = g
d.p = a
a.t = g
a.r = g
a.x = g
k.p = i
assert a.r.t.x.txt == "g"