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

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

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

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

g = A("g")
h = B("h")
m = C("m")
d = D("d")
f = B("f")

g.v = m
g.x = d
h.x = g
h.t = f
h.z = f
m.y = d
m.o = d
d.x = m
f.x = g
f.t = h
f.z = h
assert d.x.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.x: D = None
        self.txt = txt

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

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

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

g = A("g")
h = B("h")
m = C("m")
d = D("d")
f = B("f")

g.v = m
g.x = d
h.x = g
h.t = f
h.z = f
m.y = d
m.o = d
d.x = m
f.x = g
f.t = h
f.z = h
assert d.x.y.x.y.txt == "d"