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

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

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

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

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

f.v = c
f.u = i
h.w = m
h.q = i
c.u = f
c.x = f
c.r = m
m.t = c
m.p = f
i.w = m
i.q = h
assert m.p.v.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.u: B = None
        self.txt = txt

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

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

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

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

f.v = c
f.u = i
h.w = m
h.q = i
c.u = f
c.x = f
c.r = m
m.t = c
m.p = f
i.w = m
i.q = h
assert m.p.v.u.v.txt == "c"