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

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

d = A("d")
h = B("h")
k = B("k")
m = A("m")
e = B("e")

d.t = e
d.x = m
h.o = k
h.p = m
k.o = h
k.p = d
m.t = h
m.x = d
e.o = h
e.p = m
assert m.t.o.o.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: A = None
        self.txt = txt

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

d = A("d")
h = B("h")
k = B("k")
m = A("m")
e = B("e")

d.t = e
d.x = m
h.o = k
h.p = m
k.o = h
k.p = d
m.t = h
m.x = d
e.o = h
e.p = m
assert m.t.o.o.o.p.txt == "d"