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

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

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

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

b = A("b")
i = B("i")
k = C("k")
l = D("l")
j = C("j")
h = A("h")

b.x = h
i.r = k
k.r = i
l.w = b
j.r = i
h.x = b
assert h.x.x.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.r: C = None
        self.txt = txt

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

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

b = A("b")
i = B("i")
k = C("k")
l = D("l")
j = C("j")
h = A("h")

b.x = h
i.r = k
k.r = i
l.w = b
j.r = i
h.x = b
assert h.x.x.x.x.x.txt == "b"