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

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

h = A("h")
j = B("j")
k = B("k")
m = A("m")

h.u = m
j.x = m
j.y = h
k.x = m
k.y = m
m.u = h
assert j.y.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

h = A("h")
j = B("j")
k = B("k")
m = A("m")

h.u = m
j.x = m
j.y = h
k.x = m
k.y = m
m.u = h
assert j.y.u.u.txt == "h"