class A:
    def __init__(self, txt: str):
        self.r: B = None
        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

h = A("h")
n = B("n")
j = B("j")
a = A("a")
f = A("f")
b = B("b")
e = A("e")
g = B("g")
c = B("c")

h.r = c
h.x = a
n.o = j
n.v = f
j.o = n
j.v = h
a.r = j
a.x = e
f.r = n
f.x = e
b.o = g
b.v = a
e.r = c
e.x = f
g.o = j
g.v = h
c.o = n
c.v = h
assert n.o.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        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

h = A("h")
n = B("n")
j = B("j")
a = A("a")
f = A("f")
b = B("b")
e = A("e")
g = B("g")
c = B("c")

h.r = c
h.x = a
n.o = j
n.v = f
j.o = n
j.v = h
a.r = j
a.x = e
f.r = n
f.x = e
b.o = g
b.v = a
e.r = c
e.x = f
g.o = j
g.v = h
c.o = n
c.v = h
assert n.o.o.v.txt == "f"