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

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

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

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

f = A("f")
l = B("l")
m = C("m")
g = D("g")

f.v = m
l.x = m
m.q = g
m.s = g
g.x = f
g.t = l
g.u = l
assert l.x.q.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

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

f = A("f")
l = B("l")
m = C("m")
g = D("g")

f.v = m
l.x = m
m.q = g
m.s = g
g.x = f
g.t = l
g.u = l
assert l.x.q.u.x.txt == "m"