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

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

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

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

f = A("f")
a = B("a")
i = C("i")
h = D("h")
c = C("c")
g = A("g")
l = B("l")

f.v = g
f.w = h
a.w = l
a.u = l
i.x = a
i.t = a
h.z = l
h.r = f
c.x = a
c.t = l
g.v = f
g.w = h
l.w = a
l.u = a
assert h.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: D = None
        self.txt = txt

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

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

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

f = A("f")
a = B("a")
i = C("i")
h = D("h")
c = C("c")
g = A("g")
l = B("l")

f.v = g
f.w = h
a.w = l
a.u = l
i.x = a
i.t = a
h.z = l
h.r = f
c.x = a
c.t = l
g.v = f
g.w = h
l.w = a
l.u = a
assert h.r.w.r.txt == "f"