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

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

h = A("h")
j = B("j")
d = B("d")
n = B("n")
b = A("b")

h.y = b
h.o = d
j.z = n
j.t = b
d.z = j
d.t = h
n.z = d
n.t = b
b.y = h
b.o = d
assert h.y.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.o: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
d = B("d")
n = B("n")
b = A("b")

h.y = b
h.o = d
j.z = n
j.t = b
d.z = j
d.t = h
n.z = d
n.t = b
b.y = h
b.o = d
assert h.y.o.z.txt == "j"