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

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

h = A("h")
i = B("i")
f = B("f")
d = A("d")

h.u = d
h.v = d
i.z = f
i.o = f
f.z = i
f.o = i
d.u = h
d.v = h
assert f.o.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.v: A = None
        self.txt = txt

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

h = A("h")
i = B("i")
f = B("f")
d = A("d")

h.u = d
h.v = d
i.z = f
i.o = f
f.z = i
f.o = i
d.u = h
d.v = h
assert f.o.z.o.txt == "i"