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

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

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

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

d = A("d")
c = B("c")
h = C("h")
i = D("i")
g = C("g")
b = A("b")
f = D("f")

d.v = h
c.o = i
h.y = d
i.w = h
g.y = d
b.v = g
f.w = g
assert b.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.txt = txt

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

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

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

d = A("d")
c = B("c")
h = C("h")
i = D("i")
g = C("g")
b = A("b")
f = D("f")

d.v = h
c.o = i
h.y = d
i.w = h
g.y = d
b.v = g
f.w = g
assert b.v.y.v.txt == "h"