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

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

i = A("i")
b = B("b")
d = A("d")
f = B("f")
n = B("n")
c = B("c")

i.v = f
i.o = c
b.y = f
b.x = f
d.v = f
d.o = f
f.y = b
f.x = c
n.y = c
n.x = c
c.y = n
c.x = b
assert n.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.o: B = None
        self.txt = txt

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

i = A("i")
b = B("b")
d = A("d")
f = B("f")
n = B("n")
c = B("c")

i.v = f
i.o = c
b.y = f
b.x = f
d.v = f
d.o = f
f.y = b
f.x = c
n.y = c
n.x = c
c.y = n
c.x = b
assert n.y.x.y.txt == "f"