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

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

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

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

f = A("f")
g = B("g")
c = C("c")
m = D("m")
e = B("e")

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

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

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

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

f = A("f")
g = B("g")
c = C("c")
m = D("m")
e = B("e")

f.v = m
f.x = g
g.t = e
c.r = e
c.s = f
m.u = g
m.x = f
e.t = g
assert c.r.t.t.txt == "e"