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

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

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

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

f = A("f")
h = B("h")
d = C("d")
m = D("m")

f.t = d
f.u = h
h.y = d
h.z = d
h.x = m
d.x = f
m.o = h
m.q = f
assert f.u.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.u: B = None
        self.txt = txt

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

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

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

f = A("f")
h = B("h")
d = C("d")
m = D("m")

f.t = d
f.u = h
h.y = d
h.z = d
h.x = m
d.x = f
m.o = h
m.q = f
assert f.u.x.q.txt == "f"