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

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

g = A("g")
f = B("f")
b = B("b")
m = B("m")
k = B("k")
a = A("a")
n = B("n")

g.x = a
f.o = m
f.v = g
b.o = m
b.v = g
m.o = n
m.v = a
k.o = f
k.v = a
a.x = g
n.o = k
n.v = g
assert f.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

g = A("g")
f = B("f")
b = B("b")
m = B("m")
k = B("k")
a = A("a")
n = B("n")

g.x = a
f.o = m
f.v = g
b.o = m
b.v = g
m.o = n
m.v = a
k.o = f
k.v = a
a.x = g
n.o = k
n.v = g
assert f.o.o.o.txt == "k"