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

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

h = A("h")
b = B("b")
m = B("m")
l = A("l")
d = A("d")
g = A("g")
j = A("j")

h.p = g
h.o = g
b.x = l
b.r = m
m.x = h
m.r = b
l.p = d
l.o = d
d.p = j
d.o = l
g.p = d
g.o = j
j.p = l
j.o = h
assert b.r.r.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.o: A = None
        self.txt = txt

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

h = A("h")
b = B("b")
m = B("m")
l = A("l")
d = A("d")
g = A("g")
j = A("j")

h.p = g
h.o = g
b.x = l
b.r = m
m.x = h
m.r = b
l.p = d
l.o = d
d.p = j
d.o = l
g.p = d
g.o = j
j.p = l
j.o = h
assert b.r.r.r.x.txt == "h"