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

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

g = A("g")
d = B("d")
f = A("f")
j = B("j")
n = A("n")
h = A("h")
i = B("i")
m = A("m")

g.x = j
g.o = i
d.p = g
f.x = j
f.o = j
j.p = f
n.x = d
n.o = d
h.x = i
h.o = i
i.p = f
m.x = j
m.o = j
assert f.o.p.x.p.o.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
f = A("f")
j = B("j")
n = A("n")
h = A("h")
i = B("i")
m = A("m")

g.x = j
g.o = i
d.p = g
f.x = j
f.o = j
j.p = f
n.x = d
n.o = d
h.x = i
h.o = i
i.p = f
m.x = j
m.o = j
assert f.o.p.x.p.o.p.x.txt == "j"