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

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

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

b = A("b")
a = B("a")
f = C("f")
m = B("m")
h = B("h")
k = A("k")

b.x = k
b.t = f
a.t = f
f.w = k
m.t = f
h.t = f
k.x = b
k.t = f
assert a.t.w.x.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.t: C = None
        self.txt = txt

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

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

b = A("b")
a = B("a")
f = C("f")
m = B("m")
h = B("h")
k = A("k")

b.x = k
b.t = f
a.t = f
f.w = k
m.t = f
h.t = f
k.x = b
k.t = f
assert a.t.w.x.t.w.txt == "k"