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

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

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

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

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

i.x = f
c.u = m
c.r = i
c.x = f
f.s = c
j.x = f
m.u = c
m.r = i
m.x = f
assert i.x.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

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

i.x = f
c.u = m
c.r = i
c.x = f
f.s = c
j.x = f
m.u = c
m.r = i
m.x = f
assert i.x.s.r.txt == "i"