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

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

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

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

c = A("c")
g = B("g")
e = C("e")
d = D("d")
h = A("h")

c.r = e
c.w = h
g.x = c
e.x = g
d.o = c
d.t = h
h.r = e
h.w = c
assert c.w.r.x.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.w: A = None
        self.txt = txt

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

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

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

c = A("c")
g = B("g")
e = C("e")
d = D("d")
h = A("h")

c.r = e
c.w = h
g.x = c
e.x = g
d.o = c
d.t = h
h.r = e
h.w = c
assert c.w.r.x.x.w.txt == "h"