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

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

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

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

f = A("f")
m = B("m")
j = C("j")
c = D("c")

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

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

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

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

f = A("f")
m = B("m")
j = C("j")
c = D("c")

f.t = c
m.p = j
m.u = f
m.x = f
j.t = c
c.y = f
assert m.p.t.y.txt == "f"