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

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

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

j = A("j")
i = B("i")
b = C("b")
g = A("g")

j.t = i
i.y = g
i.x = g
i.p = b
b.x = i
b.y = i
g.t = i
assert j.t.p.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

j = A("j")
i = B("i")
b = C("b")
g = A("g")

j.t = i
i.y = g
i.x = g
i.p = b
b.x = i
b.y = i
g.t = i
assert j.t.p.x.y.txt == "g"