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

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

d = A("d")
h = B("h")
i = B("i")
m = B("m")
j = A("j")

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

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

d = A("d")
h = B("h")
i = B("i")
m = B("m")
j = A("j")

d.u = m
d.x = i
h.o = j
h.q = m
i.o = d
i.q = h
m.o = j
m.q = i
j.u = i
j.x = i
assert m.o.x.q.txt == "h"