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

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

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

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

f = A("f")
e = B("e")
g = C("g")
j = D("j")

f.r = j
f.x = e
e.v = g
e.y = j
g.s = e
g.t = e
g.x = f
j.z = f
j.x = f
assert f.r.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.x: B = None
        self.txt = txt

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

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

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

f = A("f")
e = B("e")
g = C("g")
j = D("j")

f.r = j
f.x = e
e.v = g
e.y = j
g.s = e
g.t = e
g.x = f
j.z = f
j.x = f
assert f.r.z.r.z.txt == "f"