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

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

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

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

f = A("f")
l = B("l")
h = C("h")
j = D("j")

f.u = j
l.t = f
l.y = j
h.x = l
h.y = f
j.p = f
assert h.y.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

f = A("f")
l = B("l")
h = C("h")
j = D("j")

f.u = j
l.t = f
l.y = j
h.x = l
h.y = f
j.p = f
assert h.y.u.p.txt == "f"