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

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

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

f = A("f")
a = B("a")
b = C("b")
l = B("l")
h = A("h")

f.x = h
a.x = h
b.s = h
b.p = l
b.t = f
l.x = h
h.x = f
assert f.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

f = A("f")
a = B("a")
b = C("b")
l = B("l")
h = A("h")

f.x = h
a.x = h
b.s = h
b.p = l
b.t = f
l.x = h
h.x = f
assert f.x.x.x.txt == "h"