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

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

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

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

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

b.r = a
b.v = g
m.v = b
m.t = a
m.r = e
m.w = c
f.w = b
f.t = m
e.r = b
c.v = b
c.t = a
c.r = e
c.w = m
a.r = b
g.w = b
g.t = m
assert f.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.v: C = None
        self.txt = txt

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

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

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

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

b.r = a
b.v = g
m.v = b
m.t = a
m.r = e
m.w = c
f.w = b
f.t = m
e.r = b
c.v = b
c.t = a
c.r = e
c.w = m
a.r = b
g.w = b
g.t = m
assert f.w.v.w.txt == "b"