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

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

k = A("k")
h = B("h")
a = B("a")
c = B("c")

k.w = h
h.x = a
a.x = h
c.x = h
assert k.w.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

k = A("k")
h = B("h")
a = B("a")
c = B("c")

k.w = h
h.x = a
a.x = h
c.x = h
assert k.w.x.x.x.txt == "a"